Skip to main content
deleted 1 character in body
Source Link
JPtheK9
  • 2k
  • 2
  • 15
  • 34

Alternatively, you could use System.Timers.Timer which is probably the most performanceperformant of any solution. The following example shows a countdown for 100 seconds.

System.Timers.Timer LeTimer;
int BoomDown = 100;
void Start ()
{
    //Initialize timer with 1 second intervals
    LeTimer = new System.Timers.Timer (1000);
    LeTimer.Elapsed +=
        //This function decreases BoomDown every second
        (object sender, System.Timers.ElapsedEventArgs e) => BoomDown--;
}

void Update ()
{
    //When BoomDown reaches 0, BOOM!
    if (BoomDown <= 0)
        Debug.Log ("Boom!");
}

Alternatively, you could use System.Timers.Timer which is probably the most performance of any solution. The following example shows a countdown for 100 seconds.

System.Timers.Timer LeTimer;
int BoomDown = 100;
void Start ()
{
    //Initialize timer with 1 second intervals
    LeTimer = new System.Timers.Timer (1000);
    LeTimer.Elapsed +=
        //This function decreases BoomDown every second
        (object sender, System.Timers.ElapsedEventArgs e) => BoomDown--;
}

void Update ()
{
    //When BoomDown reaches 0, BOOM!
    if (BoomDown <= 0)
        Debug.Log ("Boom!");
}

Alternatively, you could use System.Timers.Timer which is probably the most performant of any solution. The following example shows a countdown for 100 seconds.

System.Timers.Timer LeTimer;
int BoomDown = 100;
void Start ()
{
    //Initialize timer with 1 second intervals
    LeTimer = new System.Timers.Timer (1000);
    LeTimer.Elapsed +=
        //This function decreases BoomDown every second
        (object sender, System.Timers.ElapsedEventArgs e) => BoomDown--;
}

void Update ()
{
    //When BoomDown reaches 0, BOOM!
    if (BoomDown <= 0)
        Debug.Log ("Boom!");
}
Source Link
JPtheK9
  • 2k
  • 2
  • 15
  • 34

Alternatively, you could use System.Timers.Timer which is probably the most performance of any solution. The following example shows a countdown for 100 seconds.

System.Timers.Timer LeTimer;
int BoomDown = 100;
void Start ()
{
    //Initialize timer with 1 second intervals
    LeTimer = new System.Timers.Timer (1000);
    LeTimer.Elapsed +=
        //This function decreases BoomDown every second
        (object sender, System.Timers.ElapsedEventArgs e) => BoomDown--;
}

void Update ()
{
    //When BoomDown reaches 0, BOOM!
    if (BoomDown <= 0)
        Debug.Log ("Boom!");
}