- Home /
Question by
Epicgodofchaos · Oct 17, 2011 at 02:32 AM ·
timerscorearea
Get score in areas
Okay I've got a script that puts a timer on the upper left side of the screen, The problem is that i want this timer to be shown as either a) The time they got by the time they get to one of two areas/objects(preferably an area but an object will work too) and to just put that on the upper right of the screen. Or b) I would like some kind of score to be shown based on the timer shown in the upper right corner. Reason I'm having problems doing this myself is that i have no experience in programming area affecting or collision based functions. Help would be appreciated.
Here's what I've got so far
private var startTime;
private var restSeconds : int;
private var roundedRestSeconds : int;
private var displaySeconds : int;
private var displayMinutes : int;
var countDownSeconds : int;
private var guiTextComponent;
function Start()
{
guiTextComponent = GetComponent("GUIText");
startTime = Time.time;
}
function OnGUI () {
//make sure that your time is based on when this script was first called
//instead of when your game started
var guiTime = Time.time - startTime;
restSeconds = countDownSeconds - (guiTime);
//display the timer
roundedRestSeconds = Mathf.CeilToInt(restSeconds);
displaySeconds = roundedRestSeconds % 60;
displayMinutes = roundedRestSeconds / 60;
guiTextComponent.material.color = Color.red;
guiTextComponent.text = String.Format ("{0:0}:{1:00}", displayMinutes, displaySeconds);
if(restSeconds <= 0){
guiTextComponent.text = "YOU LOSE!!!";
return 0;
}
}
Comment