- Home /
how to reset timer when score hits an increment of 50
say you have a score script that keeps score using UnityEngine; using UnityEngine.UI; using System.Collections;
public class Score : MonoBehaviour
{
public Text scoreGUI;
public int scoreCounter;
// Use this for initialization
void Awake ()
{
scoreGUI = GetComponent <Text> ();
scoreCounter = 0;
}
// Update is called once per frame
void Update ()
{
scoreGUI.text = "Score: " + scoreCounter;
}
}
(currents in another Script i have the script so it adds a point every time a certain object is clicked, so that works)
Before i go on, here is my timer script. it counts down from 10 to 0 and on 0 it will stop counting down and it will end the game
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class TimerGUI : MonoBehaviour
{
public Text timerGUI;
public int timer;
// Use this for initialization
void Awake ()
{
timerGUI = GetComponent <Text> ();
timer = 0;
}
// Update is called once per frame
void Update ()
{
if (timer > 0)
{
timer -= Time.deltaTime;
}
if (timer = 0)
{
//lose game.
}
timerGUI.text = "Time Left: " + timer;
}
}
What ive been trying to do is figure out how i can have the timer reset to 10 every time the scoreCounter reaches an increment of 50 (50,100,150, and so on) but i cant figure out how. i know how to do it say if it would hit 50
if (score.scoreCounter = 50) { timer = 0; }
but i cant figure out how to make it reset like that every time the score hits an increment of 50.
Help would be appreciated, thanks!
Answer by DoTA_KAMIKADzE · Apr 13, 2015 at 09:19 PM
I have answered pretty much the same question some time ago, here is it.
Also don't forget to provide your instance of your Score script to TimerGUI or vice versa (depending where you will check your condition).
Alternatively you can make your scoreCounter or timer as a static variable (again depending where you will check your condition).
Your answer
Follow this Question
Related Questions
GUI & GUI Text Disappear When Publishing 6 Answers
GUIText not working properly with a timer. 1 Answer
How can I make a quest system? 2 Answers