Question by
unity_QOya9nD58KG7cg · Feb 15, 2020 at 02:26 PM ·
timerresetcountdowndeltatime
I need the timer to reset as soon as i hits 0
How do i get the timer to reset everytime i hits 0?
Script:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class SpinStopper : MonoBehaviour {
public double timer = 1;
public GameObject SpinCB;
public GameObject RealCB;
void Update()
{
timer -= Time.deltaTime;
if (timer <= 0)
{
SpinCB.SetActive(false);
RealCB.SetActive(true);
}
}
}
Comment
Answer by Steve-OTheValks · Feb 16, 2020 at 05:18 AM
Create another variable to hold the original value of timer (the value you want it to reset to each time), then set your timer variable to the original timer value once it reaches 0.
public double originalTimer = 1;
public double timer = 1;
public GameObject SpinCB;
public GameObject RealCB;
void Update()
{
timer -= Time.deltaTime;
if (timer <= 0)
{
timer = originalTimer;
SpinCB.SetActive(false);
RealCB.SetActive(true);
}
}
Your answer
Follow this Question
Related Questions
Unity3d countdown timer is not counting down 0 Answers
Need to create a Time Trial in Unity with C# 1 Answer
Timer instantly sets to zero 1 Answer
Is Time.deltaTime different on various devices? 0 Answers
Milliseconds Timer Question 1 Answer