- Home /
Question by
nivlahot2302 · Jun 05, 2020 at 09:26 AM ·
scripting problemscript.scripting beginner
What wrong with my code here?? i want to create a timer with my object move it will start timer but my timer is not moving....
public class Timer : MonoBehaviour { public Text TimerText; //private float InitialTime ; private bool StopTimerBool = true; private float MaxTimerThreshold = 99;
private float TimerCounter;
public static Timer instance { get; private set; }
void Awake()
{
instance = this;
}
private void Start()
{
// initialise TimerCounter to Initial Time
// TimerCounter = InitialTime;
TimerCounter = Time.time;
}
private void Update()
{
// if stop timer bool == true
// stop the timer
if (StopTimerBool == true)
{
// don't countdown timer
}
// if stop timer bool == false
// resume timer
else
{
// Timer Counter - 1 seconds every frame
Debug.Log("counting");
//TimerCounter = TimerCounter + 1 * Time.deltaTime;
float t = Time.time - TimerCounter;
Debug.Log("mintues");
string Minutes = ((int) t / 60).ToString();
string Seconds = ( t % 60).ToString("f2");
TimerText.text = Minutes + ":" + Seconds ;
}
// Apply Text To Screen Text
// Minute = (int)TimerCounter % 60; TimeSpan ts = TimeSpan.FromSeconds(TimerCounter);
TimerText.text = TimerCounter.ToString();
// call this when TimeCounter is after 999 seconds
if (TimerCounter >= MaxTimerThreshold)
{
OnTimerEnd();
}
}
public void OnTimerEnd()
{
Debug.Log("TIMER HAS ENDED");
// Reset Time Counter To Intiial Time
//TimerCounter = InitialTime;
}
public void StopTimer()
{
Debug.Log("Stopping Timer");
StopTimerBool = true;
}
public void ResumeTimer()
{
Debug.Log("Resuming Timer");
StopTimerBool = false;
}
}
Comment
Answer by N-8-D-e-v · Jun 05, 2020 at 06:55 PM
Your timer is set to true at the beginning, and will never start I believe
Your answer
Follow this Question
Related Questions
Trying to find the highest number than add it to itself. 2 Answers
Slowly increase motor.force 1 Answer
Move from A to B after recieving touch input 1 Answer
Need help fixing my script 1 Answer
How do I make a photography function? 0 Answers