Gui Score Question

hello all, im working on a project and i came across something that just stumped me im trying to come up with an experience system and my basic idea is to count how many instances of a certain game object there are in the level and add that to the score each second, since these game objects keep spawning the number of objects changes i dont understand how i can track this and add it to a score total in the guibox

any ideas

Really depends how you are handling these objects.

I think the best approach is not to count the objects, but to simply add +1 to a counter every time you spawn the objects in the scene.

Now if you really want to count the objects and you are storing them all in an array, you can simply use the Length property.

If you aren't storing them together, you could give them all tags and use the

FindGameObjectsWithTag function.

GameObject[] gos;
gos = GameObject.FindGameObjectsWithTag("YOURTAGNAME");
int numberOfObjects = gos.Length;

Then use WaitForSeconds or some other timing method to only do it once a second.

This really isn't a good approach though as it's not very efficient. I'd try looking at simply counting when you spawn objects.