Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

.

Discussion in 'Scripting' started by NRSM, Sep 17, 2018.

  1. NRSM

    NRSM

    Joined:
    Jun 8, 2018
    Posts:
    26
    .
     
    Last edited: Feb 7, 2022
  2. wtrebella

    wtrebella

    Joined:
    Mar 18, 2013
    Posts:
    35
    We're going to need a little more context. It would be helpful to see the code that actually enables the countdownTimer object from clicking the spawner.
     
  3. shawnrevels

    shawnrevels

    Joined:
    Aug 13, 2014
    Posts:
    86
    You need to call update.


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. public class Timer : MonoBehaviour
    4. {
    5.     public GameObject GameOverMenu, PauseButton, TimerText;
    6.     public Text timerUI;
    7.     public int countDownStartValue = 30;
    8.     public bool isCounting;
    9.  
    10.     void Start ()
    11.     {
    12.         isCounting = false;
    13.     }
    14.     void Update()
    15.     {
    16.         If(isCounting)
    17.          {
    18.  
    19.           countDownStartValue -= Time.deltaTime;
    20.           }
    21.  
    22.            if(countDownStartValue < 0)
    23.            {
    24.             isCounting = false;
    25.             }
    26.     }
    27.      
    28. }
    29.