【发布时间】:2021-11-26 20:56:50
【问题描述】:
所以我一直在尝试让难度系统在我的游戏中工作,但我遇到了一个问题,我的浮动一直重置为 1,我在另一个预制件中的预制件上有较大的脚本,而小脚本是我在“难度控制器”上的一个。我已尝试查看文件,但找不到数字 1 的任何实例我还尝试制作新的预制件以查看是否是问题但仍然是数字 1!
预制件中的脚本:
public float health;
public GameObject deathEffect;
public float difficulty;
private float destroy;
private void Update()
{
if (health <= 0)
{
//Instantiate(deathEffect, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
private void Start()
{
EnemyDifficulty(difficulty);
}
public void TakeDamage (float damage)
{
health -= damage;
}
public void EnemyDifficulty(float chance)
{
Debug.Log(chance);
destroy = Random.Range(0, 50);
if (destroy <= 3) { Destroy(gameObject); }
chance = Random.Range(chance / 2, chance * 2);
Debug.Log(chance);
if (chance <= 8 && chance >= 3)
{
BasicEnemy();
}
if (chance <= 20 && chance >= 8)
{
MediumEnemy();
}
if(chance <= 3)
{
Destroy(gameObject);
Debug.Log("Destroeyed");
}
}
public void BasicEnemy()
{
Debug.Log("basic");
}
public void MediumEnemy()
{
Debug.Log("medium");
}
}
“难度控制器”中的代码
public Enemy enemy;
public float difficultye = 5;
// Update is called once per frame
void Update()
{
enemy.difficulty = difficultye;
}
【问题讨论】:
-
哪个浮动?如果是
difficulty,那么除了DifficultyController.Update() // could the problem be that difficultye is getting modified?之外,您没有显示任何修改它的代码请显示所有相关代码。您似乎对浮点比较有问题...如果chance == 8则BasicEnemy()和MediumEnemy()都被调用,chance == 3同上->BasicEnemy()和Destroy()。在这里,我很确定您想测试这样的范围(其中 b 是边界值)a <= chance < b和b <= chance < c等。
标签: c# visual-studio unity3d