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

startTimer working for first on screen message but not the 2nd on screen message

$
0
0
Hi, I am a new user of Unity and have a basic question ... I think. I have a game where you collect coins, you cannot open a door unless you have more than 10. If you do not a message pops up saying you need 10 or more. This message has a timer attached to it so that it disappears after a few seconds. If you do have more than 10 coins the door gets destroyed and a message pops up saying well done, I also attached the timer to this one yet the message stays on screen. Any advice on getting the timer to work on that too? Will put code below this, hopefully formatting is ok. Thanks! var timer:float; var startTimer:System.Boolean; function Update () { if (startTimer == true) { timer = timer + 1; if (timer >= 200) { startTimer = false; timer = 0; GameObject.Find("messageUI").GetComponent.().text=""; } } } function OnTriggerEnter (other : Collider) { if((other.tag == "Torch")&& (ScoreCount.gscore>=10)) { Destroy(gameObject); startTimer = true; GameObject.Find("messageUI").GetComponent.().text="Well done, you unlocked the door!"; } else if ((other.tag == "Torch")&& (ScoreCount.gscore<10)) { GameObject.Find("messageUI").GetComponent.().text="10 coins needed to unlock this door. You need another " + (10-ScoreCount.gscore) + " coins!"; startTimer = true; } }

Viewing all articles
Browse latest Browse all 1875


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