Keeping A Count of Gameobjects in a Collider

Hello

I’m trying to make a control point in my game. I basically want when a unit from whatever faction enters the number for their faction rises. Or when they leave the number goes down.

However the issue I’m having is when the unit is killed in the control point. Since they don’t trigger the OnTriggerExit in my script. Does anyone know away for my script to know when a unit is destroyed and remove a value from the counter?

Keep a list of all of the units in range. Then at some regular frequency remove any that have been destroyed.

1 Like

Sadly lists are beyond my understanding, however I did a cheap way. I have it so when the gameobject enters the area they spawn a counter. And every few seconds the counter drops a point that when the collider picks up it adds to the control point.

“lists are beyond my understanding”

You may want to get over that hurdle very soon. Arrays/Lists are a very integral part to programming, especially in games.

What do you not understand about them?

2 Likes

Now is as good a time as any to fix this. Collections are fundamental to programming, and Lists are a very straight forward type of collection.

https://unity3d.com/learn/tutorials/topics/scripting/arrays?playlist=17117

https://unity3d.com/learn/tutorials/modules/intermediate/scripting/lists-and-dictionaries

1 Like

Thanks I’ll see what I can do

Hey thanks for those videos. And the push to learn this. This is for sure something great to know! Only took me a couple of hours too!

1 Like

I understand them now! Thanks for pushing me to learn them. I will now say that hurdle has been over came! :smile:

2 Likes