int not updating correctly
I'm new to C# and unity and I can't seem to sort out why my int is not updating in void update. the variable does update through a coroutine. There is no problem with the coroutine and I am also able to reduce the number back to 0 from another script but I am getting no response from the void update() line.
public int itemObject; void Start() { spawner = GameObject.FindGameObjectsWithTag("SpawnPoint"); StartCoroutine(itemSpawner()); } void update() { if(itemObject == 0) { Debug.Log("Update works"); } } IEnumerator itemSpawner() { while (itemObject < 2) { int spawn = Random.Range(0, spawner.Length); Instantiate(item, spawner[spawn].transform.position, Quaternion.identity); yield return new WaitForSeconds(2); itemObject += 1; } } }
Answer by lodendsg · Jun 20, 2021 at 04:20 PM
you have update declared as
void update()
{
if (itemObject == 0)
{
Debug.Log("Update works");
}
}
that is incorrect it must be capitalized ... casing matters in C# so it should be
void Update()
{
if (itemObject == 0)
{
Debug.Log("Update works");
}
}
Also small note your itemSpawner method should also be capitalized ... in C# the common naming standard is that a method name should always be capitalized can camel cased