- Home /
Question by
HappyfaceZzZ · Mar 11, 2014 at 03:11 PM ·
wont stop
How to make Timer stop upon Death?
Hello! I'm trying to make my timer to stop when the player dies. It's currently only counting, but nothing happens when I die.
The code:
using UnityEngine;
using System.Collections;
public class Timer : MonoBehaviour {
public GUIText timerTex; //Text for GUI
public float levelTimer = 0f;
public bool updateTimer = false;
void start()
{
updateTimer = true;
}
void End()
{
updateTimer = false;
}
void Update()
{
if (updateTimer == true)
{
levelTimer += Time.deltaTime;
timerTex.text = levelTimer.ToString ();
}
}
void OnTrigger (Collision2D col)
{
if(col.gameObject.tag == "Player")
{
updateTimer = false;
}
}
}
Please help! :)
Comment
Answer by saruul34 · Mar 11, 2014 at 03:33 PM
void OnTriggerEnter2D (Collider2D col)
{
if(col.gameObject.tag == "Player")
{
updateTimer = false;
}
}
OR:
void OnCollisionEnter2D (Collision2D col)
{
if(col.gameObject.tag == "Player")
{
updateTimer = false;
}
}
Your answer
Follow this Question
Related Questions
For Loop Won't Stop Running... 1 Answer
Mouse Look Script 1 Answer
Particle system stop? 3 Answers
I can't create a world border? 1 Answer
Stop player movement if it's Raycast hits an object 0 Answers