Hello guys! There’s this problem I have where I have a quite simple code which after a button has been clicked, the event system runs a public function Build ().
It’s worth mentioning that “prefabConst” is a under construction sprite, and “prefab” is the finished building sprite. So everything works flawlessly until the Construction coroutine. Sometimes and for no apparent reason (and I repeat, ONLY sometimes) it doesn’t run. I’m not sure if it doesn’t run but the construction sprite persists which only tells me it didn’t run in the first place.
I failed to find any patterns in why it decides not to work (like clicking too fast).
Does anybody have an idea on how could I approach this issue?
public void Build () {
x = Random.Range (-4.5f, 4.5f);
y = Random.Range (-2.5f, 2.5f);
z = 0;
pos = new Vector3 (x, y, z);
GameObject storeMe = Instantiate (prefabConst, pos, Quaternion.identity);
StartCoroutine (Construction(storeMe));
}
IEnumerator Construction (GameObject destroyMe) {
yield return new WaitForSeconds (5);
Instantiate (prefab, destroyMe.transform.position, Quaternion.identity);
Destroy (destroyMe);
}