When the button should go off it appears/disappear someone could help? Code (CSharp): IEnumerator BottoneCuore1 () { yield return new WaitForSeconds(4f); BottoneCuore.SetActive (false); } IEnumerator BottonScudo1 () { yield return new WaitForSeconds(4f); BottoneScudo.SetActive (false); } IEnumerator BottoneSpari1 () { yield return new WaitForSeconds(4f); BottoneCuore.SetActive (false); } Code (CSharp): i } if(HP <=3&&cuori >=1) { BottoneCuore.SetActive(true); StartCoroutine(BottoneCuore1()); } if(HP <=2&&scudo >=1) { BottoneScudo.SetActive(true); StartCoroutine(BottonScudo1()); } if(HP == 7&&spari>=1||HP==5&&spari>=1) { BottoneSpari.SetActive (true); StartCoroutine(BottoneSpari1()); } }
If the second code is executed in Update: You keep setting the object to active and start the coroutines several times (as long as the conditions evaluate to true). So the Coroutine might end and sets the state of the object to false for a very short time until the next Update comes along and sets it back to true. Then the other coroutines which were started by "mistake" just do the same.