Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

On trigger enter.. exit. Keeping track. help

Discussion in 'Physics' started by bassamsiam, Jan 13, 2021.

  1. bassamsiam

    bassamsiam

    Joined:
    Jun 9, 2020
    Posts:
    2
    Hello. I've been working on a castle defence game and I am having an issue with triggers.

    Atm when any ally unit hits into any enemy unit they stop moving forward and start attacking. They also start taking damage based on the specific tag the enemy has. When a unit dies they go flying back in a death animation and I use the on trigger exit to stop the attacking and damage and start running again. All this works perfectly... to a point.

    Where I'm having trouble is if 2 or more of your units enter the same enemy trigger they all take damage. I need a relatively easy way to make it where if more than 1 unit is in the trigger of the same enemy they only call the atk part of their script and only take damage when they are the only ally unit inside that trigger.

    I was going to paste code here but the code is between multiple scripts.

    Thanks.
     
  2. bassamsiam

    bassamsiam

    Joined:
    Jun 9, 2020
    Posts:
    2
    I figured it out myself. Had to put a public bool on the units. After their hit with the first trigger set it to false if hit same trigger while false take no damage until true with checks based on enemy targets atk speed. It's working yay