- Home /
Question by
AndrewVanB · Nov 25, 2016 at 07:56 AM ·
c#timertimer countdown
Trying to make a timer work..
I've been fiddling around with this for about an hour now trying to make it work, the best I've been able to do is have it run, but then it resets the timer to 2 every update.
My goal has been to have the CountDown method start when the conditions are met, but not loop in the ball update method.
Ball Class:
void Update () {
//If superBallActive is true, start 2 second countdown
if (superBallActive && counter.timerTrigger) {
counter.CountDown(2f);
}
Timer Class:
using UnityEngine;
using System.Collections;
public class CounterClass : MonoBehaviour {
public bool timerTrigger = true;
private Ball ball;
void Start() {
ball = GameObject.FindObjectOfType<Ball>();
}
public void CountDown(float t) {
// timerTrigger = false;
// while (timerTrigger) { // Crashes unity
Debug.LogError("CountDown Started");
if (t > 0) {
t -= Time.deltaTime;
} else if (t <= 0) {
CountDownEnded();
Debug.LogError("Count Down Ended.");
}
Debug.LogWarning("Time: " + t);
// }
}
void CountDownEnded() {
ball.superBallActive = false;
timerTrigger = true;
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
make a countdown timer 1 Answer
Distribute terrain in zones 3 Answers
timer not ticking down 2 Answers