Score Gui

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;
     }
}

Let me know if that works.

Yes i’am accessing ‘Counter’ from other scripts.But my question is how can i make my final score show after time runs out.Any help? Thank you.

function onGui()
{
if( time == 0)
displayScore();
}

Thank You but how can i make code from this script use the score from another script?

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.

Read this and then read this and lastly read this.

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 :smile:

You would want to stop your timer when it reaches 0.
Simple condition.

I know i added line:

if (restSeconds == 0) {
        print ("Time is Over");
      
        
        //do stuff here
        GUI.Label (Rect (100, 100, 100, 100), "Score: " + Counter);
        
        restSeconds.Stop();
        
    }

“restSeconds.Stop();”

but it stops for a sec. But it somehow goes to - and hides Score?
Any help?Thank you :wink:

Ok srry i got it.But if someone needs it just change from

to

Thanx any way…

If you have any trouble with it, Try if(restSeconds<=0)

That should stop it at 0 and not -1

how can i add seconds from one script to timers script.Something like

function OnMouseOver()
{
 if(Input.GetMouseButtonDown(0))
 {
 	Destroy(gameObject);
  GuiScript.restSeconds += 50;
 }
}

Timer Script is Up^
Thank you… :slight_smile:

Bump?

Really?Nobody?

You’re basically asking the same question you asked before…

The3DKnight

Use this for your score :

Attach this on a your Enemy - as a separate script

function OnCollisionEnter(boom : Collision) {

if(boom.gameObject.tag == “Bullet”)
{
life +=1;
if(life == 5)
Destroy(gameObject);
}
}

function OnDestroy() {
ScoreScript.score += 100;
}

Notice that this script above makes your enemies have Life

So basicaly what this up here ^^ means if the enemy is destroyed then your score goes up by 100

And this on any GameObject

static var score : int = 0;
var myFont : Font;

function OnGUI() {
GUI.skin.font = myFont;
GUI.Label(Rect(0, 1, 200, 40), “Score:” + score);
}

And if you want a complete EnemyAI Script that follows the player, has a life and die function tell me ill reply :smile:

After the :
if (restSeconds == 0) {

print (“Time is Over”);
}

Type in Awake();
so it will be like this

if (restSeconds == 0) {

print (“Time is Over”);
Awake();
}

This will make the script run again and again reapeating like a loop