Search Unity

Buttons doesn't disappear

Discussion in 'Scripting' started by simone9725, Feb 13, 2016.

  1. simone9725

    simone9725

    Joined:
    Jul 19, 2014
    Posts:
    234
    When the button should go off it appears/disappear someone could help?
    Code (CSharp):
    1. IEnumerator BottoneCuore1 ()
    2. {
    3. yield return new WaitForSeconds(4f);
    4. BottoneCuore.SetActive (false);
    5. }
    6. IEnumerator BottonScudo1 ()
    7. {
    8. yield return new WaitForSeconds(4f);
    9. BottoneScudo.SetActive (false);
    10. }
    11. IEnumerator BottoneSpari1 ()
    12. {
    13. yield return new WaitForSeconds(4f);
    14. BottoneCuore.SetActive (false);
    15. }
    16.  
    Code (CSharp):
    1. i
    2.     }
    3.         if(HP <=3&&cuori >=1)
    4.         {
    5.             BottoneCuore.SetActive(true);
    6.             StartCoroutine(BottoneCuore1());
    7.         }
    8.         if(HP <=2&&scudo >=1)
    9.         {
    10.             BottoneScudo.SetActive(true);
    11.             StartCoroutine(BottonScudo1());
    12.         }
    13.         if(HP == 7&&spari>=1||HP==5&&spari>=1)
    14.         {
    15.             BottoneSpari.SetActive (true);
    16.             StartCoroutine(BottoneSpari1());
    17.         }
    18.     }
    19.  
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    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.
     
  3. simone9725

    simone9725

    Joined:
    Jul 19, 2014
    Posts:
    234
    Could you give me an example please?