Answer the question
In order to leave comments, you need to log in
How to stop the timer when a character dies, uinty?
How to stop the timer when a character dies?
Here is the C# code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Timer : MonoBehaviour
{
public Text scoreText;
void Start () {
InvokeRepeating("RunTimer", 1, 1);
}
void RunTimer() {
scoreText.text = (int.Parse(scoreText.text) + 1).ToString();
}
}
Answer the question
In order to leave comments, you need to log in
Implement the timer not through InvokeRepeating, but through something more controlled - Update, for example, or a coroutine.
Specifically in your case:
void RunTimer() {
if (IsAlive())
scoreText.text = (int.Parse(scoreText.text) + 1).ToString();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question