Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Keeping A Count of Gameobjects in a Collider

Discussion in 'Scripting' started by RaGEn, Jul 7, 2017.

  1. RaGEn

    RaGEn

    Joined:
    Feb 3, 2015
    Posts:
    88
    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?
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Keep a list of all of the units in range. Then at some regular frequency remove any that have been destroyed.
     
    RaGEn likes this.
  3. RaGEn

    RaGEn

    Joined:
    Feb 3, 2015
    Posts:
    88
    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.
     
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    "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?
     
    RaGEn and Kiwasi like this.
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    RaGEn likes this.
  6. RaGEn

    RaGEn

    Joined:
    Feb 3, 2015
    Posts:
    88
    Thanks I'll see what I can do
     
  7. RaGEn

    RaGEn

    Joined:
    Feb 3, 2015
    Posts:
    88
    Kiwasi likes this.
  8. RaGEn

    RaGEn

    Joined:
    Feb 3, 2015
    Posts:
    88
    I understand them now! Thanks for pushing me to learn them. I will now say that hurdle has been over came! :D
     
    TaleOf4Gamers and Kiwasi like this.