- Home /
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
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
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
SO PLEASE HELP ME
im almost done with my game all i need is that
Answer by FLASHDENMARK · Jun 25, 2011 at 09:06 PM
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.
ok what do i attach this script to?? cause it aint working
it just gives me a zero the whole time
I changed it up a little, should work now and be more understandable.
Answer by bittam · Jun 25, 2011 at 08:50 PM
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?
go with what orange lightening said.. i think i got confused with another similar sounding post.
Your answer
Follow this Question
Related Questions
Refferencing to other scripts 1 Answer
Animation Script not working. 1 Answer
Audio play when object hit collision. 2 Answers
Gradually change distance fog over time with a collider object. 1 Answer
Respawn Problem 2 Answers