Hi all i have one question.
I’ve got timer count down script and score script.But how can i add like when my time is 0 that score from my score script shows on screen ?Thank you.
Here are scripts.
Timer Script
private var startTime;
private var restSeconds : int;
private var roundedRestSeconds : int;
private var displaySeconds : int;
private var displayMinutes : int;
var countDownSeconds : int;
var mySkin : GUISkin;
function Awake() {
startTime = Time.time;
}
function OnGUI () {
GUI.skin = mySkin;
var guiTime = Time.time - startTime;
restSeconds = countDownSeconds - (guiTime);
if (restSeconds == 60) {
print ("One Minute Left");
}
if (restSeconds == 0) {
print ("Time is Over");
//do stuff here
}
roundedRestSeconds = Mathf.CeilToInt(restSeconds);
displaySeconds = roundedRestSeconds % 60;
displayMinutes = roundedRestSeconds / 60;
text = String.Format ("{0:00}:{1:00}", displayMinutes, displaySeconds);
GUI.Label (Rect (400, 25, 100, 30), text);
}
And here’s my Score script…
var mySkin : GUISkin;
static var Counter : int;
function OnGUI()
{
GUI.skin = mySkin;
var GuiSkin : GUISkin;
GUI.Label (Rect (10, 10, 100, 20), "Score: " + Counter);
}
function OnTriggerEnter(other : Collider)
{
if(other.tag == "the tag for your player object")
{
GuiScript.Counter += 1;
}
}
Are you accessing the variable “Counter” from another script? If not, then remove “static” and use “private” instead, to make it un-editable in the inspector.
You may also want to make the second function of your score code more along the lines of:
private var Counter: int;
function OnTriggerEnter(other: Collider) {
if (other.tag == "the tag for your player object") {
Counter = Counter + 1;
}
}
I think your best and simplest bet would be to combine the scripts and do it that way. The only time you might not want to is if you disable one script but want/need the other to keep working.
Ok guys thanx a lot!!!But i’ve got one more problem.It’s that when my timer gets to 0.The score appears but only for few second then it goes -1,-2,-3,-4…And the Score text disappears.Ooo(and i joined the scripts)…Thank you for your time