- Home /
How to make a coundown of destroyed objects ?
I want the game to show the number "5" on the top of the screen . I made some Spheres so if you click them the are destroyed . I want the number to change to 4 when I click on 1 ball , 3 when I click on 2 balls ... At 0 I want it to Load another scene .
How can I do it ? help please ! THX !
Answer by Mander · Aug 30, 2012 at 02:09 PM
1.-u need an empty game object with an script attached to count to 0 and to display ur text. 2.-u need a GUIText on ur screen. 3.-u need a the script to destroy ur balls.
so based on what u already have.
make an empty gameobject leve it anywhere. this will only hold the previous mentioned script so it wont get destroyed and stop working.
1st script: name it whatever u want ill name it "GUIsphere"
//1st declare a variable to hold ur GUIText and controll its properties and ur cont variable
var referenceToText : GUIText;
var number : int;
//remember to assign the guitext on the inspector tab
//then in the update call the referenceToText and the number and printit every Update
void Update(){
referenceToText.Text = ("Spheres left:"+number);
}
then on ur script where u destroy each ball. just add the following line
GameObject.Find("emptyGameobject").GetComponent("GUIsphere").number -=1;
//emptyGameobject is the name of the empty gameobject that holds the GUI script
Hey Fattie , I know how to use GUI , I needed help in the whole script . thx anyway :)
$$anonymous$$ander , Thank you , you helped me a lot , but I didn't do exactly what you did :)
Now i need help in : how to load another level on 0 .
I need you to help me again , you probably didn't noticed the last sentence because I edited the comment .
normaly u should be doing another question. those are the rules of the UAnswers but ill help u since is an ez line.
just on ur update on the GUIsphere script make an if (number == 0){ Application.LoadLevel("level2"); }
I did it too but I forgot to right two equals so it gave me an error . Now I have another problem , It doesn't load the level but not gives any error. BTW , I did mention this question at the end of the thread , if you will look .