- Home /
how to make a countdown 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 AlwaysSunny · Aug 30, 2012 at 04:41 PM
There are a ton of different ways you could do this. The most straightforward way to display the count on the screen is using the GUI. If you have a GUI Style with a font you want to use, you can create a GUI Label which will display any text you want, like the number of objects remaining.
To keep track of your GameObjects, you have a lot of options. If you create them via code at runtime, you can just keep a reference to them in a List. When they're destroyed, remove them from the list. When the list Count is zero, load your next scene.
If you're not adding your objects at runtime, you could have a script with a public List<> variable, to which you add each Sphere object in the inspector.
A more expensive way would be to have a script which constantly asks the scene how many sphere objects are in it. This can be done a number of ways, such as with GameObject.FindWithTag().
You ought to explore all the different methods available for getting references to objects and the different methods of sharing those references between scripts. It's very basic and important info for programming, so there's a ton of info about it already. :)