- Home /
Question by
The3rdGuardian · Dec 08, 2019 at 09:58 AM ·
2d-platformertimecodepagecalling
cant figure out how to code a Unity2D Timer that ends game
https://github.com/The3rdGuardian/Code-issues
attached is git file with 2 scripts in it. The Countdown script displays a countdown based on time.deltatime while the player script controls my player. I'm trying to work out to when the countdown reaches 0, if the player hasn't beat the game then the lose game function that i have in my player code is called.
Can anyone help me figure out how to do this?
Comment
Answer by bhavinbhai2707 · Dec 08, 2019 at 10:23 AM
Simply, keep a bool in PLayer.cs script saying public bool levelFinished = false;
and set it to true when the player wins the game.
In your timer script,
if (startingTime < 0)
{
startingTime = 0;
if(FindObjectOfType<Player>().levelFinished == false)
{
//Your GameOver Logic
}
}