- Home /
Time limit on my game with selection menu
Hello, I Need help for this game. I would like the game to run for a max of 3 mins then a selection menu comes up
I would like the that to pop up when 3 mins are up so then the player can select quit the game, Go back to the main menu or reset that bit
Please help
You can use Time.deltaTime to add the time that has passed since the last frame to a variable:
var timer : float = 0; // keeps track of time that has passed
var maxTime : int = 60 * 3; // stop after 3 $$anonymous$$utes
var show$$anonymous$$enu : boolean = false;
function Update() {
if(timer >= maxTime)
{
show$$anonymous$$enu = true;
}
else
{
timer += Time.deltaTime; // add time that has passed to variable
}
}
function OnGUI() {
if(show$$anonymous$$enu)
{
// your GUI stuff here
}
}
I added a boolean variable to the code in my answer so that you can add the menu code into the OnGUI() function.. I'm assu$$anonymous$$g that your menu code is in a OnGUI() function :)
hehe i havent made the code of it yet XD ive only made the piucture of it i need help with that too hehe sorry for not being more discriptive xD
Have a check around the web, you'll find plenty of useful posts, websites and tutorials to help you create a GUI menu.. Creating a menu really is another matter altogether and will take a bit of time. Once you got your menu working, then you can try adding it to the code in my answer.. if you have any trouble with that then let me know :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613074443im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Timer doesn't count 0 Answers
Make a button quit the game, Unity 4.6 UI C# 1 Answer
Quit application before relaunching to specific scene 1 Answer
Menu to game play JAVA Script 3 Answers
Timer variable set to zero 2 Answers