Search Unity

Delay before gameobject set active couritine

Discussion in 'Scripting' started by chez_jmr, Feb 19, 2021.

  1. chez_jmr

    chez_jmr

    Joined:
    Mar 20, 2020
    Posts:
    8
    Hello,

    I try to have a delay for 3 seconds before the game object(two panels) is activated when a button is pressed. I assigned the button on click the panelview() but I could not find how to write the couritine inside as the IEnumerator.

    Can somebody help me? Thanks

    Here is the part of the code I want to combine the couritine into:

    Code (CSharp):
    1.    
    2.      public void panelview()
    3.     {
    4.        
    5.  
    6.         if (totalenergy == 0)
    7.         {
    8.              panel2.gameObject.SetActive(true);
    9.  
    10.         }
    11.         if (totalenergy >= 1)
    12.         {
    13.    
    14.         panel.gameObject.SetActive(true);
    15.  
    16.         }
    17.     }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742