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

If statements in OnTriggerEnter2D

Discussion in '2D' started by epochplus5, Oct 28, 2020.

  1. epochplus5

    epochplus5

    Joined:
    Apr 19, 2020
    Posts:
    677
    Am I correct in saying that if you have tags in if statements in the OnTriggerEnter2D methods, the collision layers wont work?
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    No, collision layers and tag comparisons are completely separate things.
    I'm guessing you're having an issue where you're trying to compare the tag of an object that entered a trigger collider, but the condition isn't resolving to true?
     
  3. epochplus5

    epochplus5

    Joined:
    Apr 19, 2020
    Posts:
    677
    I have a collision method
    and in it im checking if the object is being hit by bullets a missile or guns
    but the object wasnt exploding when my player hit into it despite them being on the same layer
    but i fixed it by if player in the method.