Timer Help,Timer
public class Timer : MonoBehaviour
{
bool stopwatchActive = false;
float currentTime;
public Text currentTimeText;
// Start is called before the first frame update
void Start()
{
currentTime = 0;
}
// Update is called once per frame
void Update()
{
if (stopwatchActive == true)
{
currentTime = currentTime + Time.deltaTime;
}
TimeSpan time = TimeSpan.FromSeconds(currentTime);
currentTimeText.text = time.ToString(@"mm\:ss\:fff");
}
public void StartTimer()
{
stopwatchActive = true;
}
public void StopTimer()
{
stopwatchActive = false;
}
}
This is my current timer, It starts and stops right now on text button presses. How can I make it start/stop when I pass through a trigger object? ,How do I make a timer that resets once I click the start button or pass an object that has a trigger. I currently have at the moment a timer that starts on a text button press and stops on a different button press.
public class Timer : MonoBehaviour
{
bool stopwatchActive = false;
float currentTime;
public Text currentTimeText;
// Start is called before the first frame update
void Start()
{
currentTime = 0;
}
// Update is called once per frame
void Update()
{
if (stopwatchActive == true)
{
currentTime = currentTime + Time.deltaTime;
}
TimeSpan time = TimeSpan.FromSeconds(currentTime);
currentTimeText.text = time.ToString(@"mm\:ss\:fff");
}
public void StartTimer()
{
stopwatchActive = true;
}
public void StopTimer()
{
stopwatchActive = false;
}
}
This is what I currently have, any ideas on what to add to make it so I can reset it to 0 and any ideas on how to make it start/stop through a trigger object?
Your answer
Follow this Question
Related Questions
C# access a generic list from another controller -1 Answers
OnTriggerEnter/Exit Rapid Firing? 0 Answers
1 Restart Scene multiple levels. Is this possible? - C# - 1 Answer
Using Multiple Activated Triggers to trigger a Separate Event. 0 Answers
(SOLVED) Need help with Script that is supposed to get components of an AI and change them 1 Answer