- Home /
How To Reset Timer on a Collision (C#)
Here is my timer script.
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class TimeManager : MonoBehaviour {
public float startingTime;
private Text theText;
public GameObject gameOverScreen;
// Use this for initialization
void Start () {
theText = GetComponent<Text> ();
}
// Update is called once per frame
void Update () {
startingTime -= UnityEngine.Time.deltaTime;
if (startingTime <= 0) {
gameOverScreen.SetActive (true);
}
theText.text = "" + Mathf.Round (startingTime);
}
}
Here is my coin script.
using UnityEngine; using System.Collections;
public class CoinPickup : MonoBehaviour {
public int pointsToAdd;
void OnTriggerEnter2D (Collider2D other)
{
if (other.GetComponent<PlayerControler> () == null)
return;
ScoreManager.AddPoints (pointsToAdd);
Destroy (gameObject);
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to reset timer? (C#) 3 Answers
Timer variable set to zero 2 Answers
Resetting a timer after game over 1 Answer
Distribute terrain in zones 3 Answers