(Help Please) How to load new level one count down time hits zero?
Hello, i am trying to do create a game, but I am trying to have a countdown timer that once it hits zero it will load the game over scene. I currently have the count down timer working perfectly, but I am a little bit confused on where to put the once the timer ends it will load the game over scene.
here is my script for the timer section
and then here is my code that is attached to the timer for my player controller
please help me in any way possible! I am so close to finishing my game but I have completely hit a near dead end. Thanks for any help in advance
If you want to load new gameover scene when timer ends for thet you have UpdateTimer() in TimerController.
if (remainingTime > 0.0f)
{
SetTimerString(remainingTime);
}
else
{
// Load gameover scene
}
Hey so that worked perfectly! I just have kne more question. I have the countdown timer set up and everything. But I also have a respawn script attached to my player and a platform so if the player falls off platform it respawns in the same spot as if the game just started with the countdown timer continuing. So my issue is I can't figure out when the player falls off I want to subtract lets say 5 seconds from the countdown timer. So lets say the player falls off platform at 60 seconds remaining i want it to subtract 5 seconds and then respawn the player. I have two scripts that I am using. Here is the TimerController script
And here is the respawn script.
http://pastebin.com/ZJQ$$anonymous$$pFAq
Please email me at jeffreyyourman@gmail.com
You can put a collider underneath your platform and when the player hits the collider you know he has fallen off the platform and respawn him. Or you can just check the vertical position of you player with respect to the platform and know if he is below it.
Answer by ransomink · Aug 29, 2015 at 07:37 PM
You will need to declare var remainingTime outside of Update() in order to access it from another script.
You can keep it private and create a getter/setter, then set its new value after the player falls; Or, use a function created inside the TimeController class and call it:
public void function SubtractFromTimer(float time)
{
remainingTime -= time;
}
As @OG23 mentioned, you can place a collider/trigger underneath the platform and when the player enters said collider, respawn the player and subtract from the remaining time.
Hope this helps!
Your answer
Follow this Question
Related Questions
I'm confused, Application.loadedLevelName not working 1 Answer
Duplicate scene will make Awake function problem? 0 Answers
Game works fine inside editor but takes forever to load after build. 0 Answers
DateTime Timer not working when loading the correct timer amount?? 1 Answer
Trying to create a timer that runs outside the Game 1 Answer