I have a prefab of an asteroid and a script that creates instances at game start. I want to have a counter (OnGUI) that shows how many remain as I destroy them one by one with my badass lasers…
function OnGUI () {
GUI.Label (Rect (10,10,60,30), "Rocks left " + WHAT GOES HERE?);
}
I have tried all the FindObject(s) but can’t find a way for it to tell me how many remain…? Also trying to figure out the right way to “count” how many times a button has been pressed. Thanks!
add a static variable called instanceCount to the asteroid class and increment it in the awake function of the asteroid class and decrement it in OnDisable
Surely someone can help me further… FindObjects seems like the easiest way to do this, but it is giving me a hard time to say the least. I am sure its something simple I am missing. The scripting guide isn’t much help as it’s examples are too open ended.
Why isn’t there a FindObjectsOfName…?
Sounds easy but I am lost on how to do it. Some exapmle code would be excellent. Thanks!
Length worked great. I spawn the asteroids from a script at game start. So now it counts how many there are, when i destroy one it decrements, when there are none left it shows 0. Thanks a million!