Attempt counter

Alright I’m going to make this as easy and simple as i can make it…

I’m working on this game IDK what to call it yet…

Heres sum pics of it

alt text

Well Anyway as you can see on the pic there’s a counter script im using but i dont want that!!

I wanna use a script that counts how many times a script is used.

Under each level theres a cube with a collider attached to it
and when i hit that collider it will send me to a fixed respawn point

alt text

Heres the script for the respawn thing on the cube


var destination : Transform;

function OnTriggerEnter(other : Collider) {
other.transform.position = destination.position;
}


Now what i want to do is have a script that makes a gui on my camera and tells me how many times i hit that collider…

Therefore making an attempt counter

Kinda like in the impossible game

alt text


SO PLEASE HELP ME

im almost done with my game all i need is that

Add a OnTriggerExit function (and make sure the object.name that is exiting the trigger is the same object.name that had entered the trigger). if the object.name’s match, you can increment your counter then. does this make sense?

var attemptsCounter : GuiText; // Add a guiText here

var destination : Transform; // Where you want the player to spawn when it collides with the object.

var attempts = 0;

function OnTriggerEnter (hit : Collider)
{
if(hit.gameObject.tag == "Give the object you are colliding with a tag and write it here")
    {
transform.position = destination.position;
attempts += 1;
     }
}

function Update ()
{
attemptsCounter.text = ""+ attempts;
}

Attach this to your player.

Very easy just adding a variable called attempts that gets added to when the player collides with the object and printing it out on a GUIText.

BTW What is that font called? It looks sweet.

EDIT: Sorry I can´t format the code properly.