Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

Mini Game Timer - Unity 2017

$
0
0
Hello everyone! I am currently in the middle of my first game in Unity, so please bear with me haha. I have been having trouble for the past couple days trying to create a timer that starts when "e" is pressed and lasts 60 seconds. I currently have it set up so that, while in a trigger, and after "e" is pressed, it deactivates the current character and activates another character in a different part of the scene. It also activates a GUI label that displays a score (this all works). The problem is, I can't make it so that everything is reset after 60 seconds. I have tried many different ways that I have found across the Internet and nothing seems to work. Please ask if you need anymore information. Thanks! **NOTE - I am using JavaScript** var TimmyTrash : GameObject; //new player player var TimmyThicc : GameObject; //original player var TrashScore : GameObject; //GUI label var TimeOut : GameObject; //GUI label that displays "Time's up!" var TimerStart : boolean; var seconds = 60; //total time to play game TimerStart = false; //makes sure player is in range, and when "e" is pressed the player is //'moved' and the game begins function OnTriggerStay (Collider) { if (Input.GetKeyDown ("e")) { TimmyTrash.SetActive(true); TimmyThicc.SetActive(false); TrashScore.SetActive(true); TimerStart = true; StartCounting(); } } function StartCounting() { //invokes the Count function every second InvokeRepeating ("Count", 0, 1); } //subtracts 1 from 'seconds' every second, and when the seconds variable gets <= 0, //the game stops and the original player is reactivated. function Count() { if (seconds > 0) { seconds --; } else { TimeOut.SetActive(true); TimmyTrash.SetActive(false); yield WaitForSeconds (5); { //after displaying the "Time's Up" GUI Label (TimeOut), I wait 5 seconds before reseting TimeOut.SetActive(false); TimmyThicc.SetActive(true); TrashScore.SetActive(false); } } }

Viewing all articles
Browse latest Browse all 1875

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>