Search Unity

How can ı activate my gameobject after wait little bit ?

Discussion in 'Editor & General Support' started by Lupinder, Mar 23, 2021.

  1. Lupinder

    Lupinder

    Joined:
    Oct 6, 2018
    Posts:
    85
    I created a panel for my game over scene. I want to activate after one player reaches 3 in scoreboard. Problem is my panel is not showing. What is wrong about this script ? Thanks for help.

    Code (CSharp):
    1. public float speed;
    2.     public Text countText;
    3.     public Text winText;
    4. public GameObject panel;
    5.  
    6.     private float t;
    7.  
    8.     // Create private references to the rigidbody component on the player, and the count of pick up objects picked up so far
    9.     private Rigidbody rb;
    10.     private int count;
    11.  
    12.     // At the start of the game..
    13.     void Start()
    14.     {
    15.       // Make the game run as fast as possible
    16.  
    17.         // Assign the Rigidbody component to our private rb variable
    18.         rb = GetComponent<Rigidbody>();
    19.  
    20.         // Set the count to zero
    21.         count = 0;
    22.  
    23.         // Run the SetCountText function to update the UI (see below)
    24.         SetCountText();
    25.  
    26.         // Set the text property of our Win Text UI to an empty string, making the 'You Win' (game over message) blank
    27.         winText.text = "";
    28.     }
    29.  
    30.     // Each physics step..
    31.     void FixedUpdate()
    32.     {
    33.         // Set some local float variables equal to the value of our Horizontal and Vertical Inputs
    34.         float moveHorizontal = Input.GetAxis("Horizontal");
    35.         float moveVertical = Input.GetAxis("Vertical");
    36.  
    37.  
    38.         // Create a Vector3 variable, and assign X and Z to feature our horizontal and vertical float variables above
    39.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    40.  
    41.         // Add a physical force to our Player rigidbody using our 'movement' Vector3 above,
    42.         // multiplying it by 'speed' - our public player speed that appears in the inspector
    43.         rb.AddForce(movement * speed);
    44.     }
    45.  
    46.     // When this game object intersects a collider with 'is trigger' checked,
    47.     // store a reference to that collider in a variable named 'other'..
    48.     void OnTriggerEnter(Collider other)
    49.     {
    50.         // ..and if the game object we intersect has the tag 'Pick Up' assigned to it..
    51.         if (other.gameObject.CompareTag("Pick Up"))
    52.         {
    53.  
    54.             // Make the other game object (the pick up) inactive, to make it disappear
    55.             other.gameObject.SetActive(true);
    56.  
    57.             // Add one to the score variable 'count'
    58.             count = count + 1;
    59.  
    60.             // Run the 'SetCountText()' function (see below)
    61.             SetCountText();
    62.         }
    63.     }
    64.  
    65.     // Create a standalone function that can update the 'countText' UI and check if the required amount to win has been achieved
    66.     void SetCountText()
    67.     {
    68.         // Update the text field of our 'countText' variable
    69.         countText.text = ": " + count.ToString();
    70.  
    71.         // Check if our 'count' is equal to or exceeded 12
    72.         if (count >= 3)
    73.         {
    74.             {
    75.                 // Set the text value of our 'winText'
    76.                 winText.text ="WİNNER!";
    77.  
    78.                 {
    79.                     StartCoroutine(WaitForIt(2.1F));
    80.                 }
    81.                 IEnumerator WaitForIt(float waitTime)
    82.                 {
    83.                     yield return new WaitForSeconds(waitTime);
    84.  
    85.         gameObject.SetActive(true);
    86.                 }
    87.  
    88.                 {
    89.  
    90.                 }
     
  2. Lupinder

    Lupinder

    Joined:
    Oct 6, 2018
    Posts:
    85
    Okey ı solved. I just added panel. "panel.gameObject.SetActive(true);"