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

OnColliderEnter2D() on 2 scripts attached to the same Object

Discussion in '2D' started by martibergoglio, Oct 27, 2015.

  1. martibergoglio

    martibergoglio

    Joined:
    May 28, 2015
    Posts:
    14
    Hi, this is my problem, i have 2 scripts attached to the same GameObject and both call OnColliderEnter2D(), how is the behavior in this case? is there an Inspector order of execution? Always run first the same script and i don´t know why.

    The problem is that one call TakeDamage() and the other call NearCheckpoints(), the last one search for nears checkpoints and move the player if any checkpoint is triggered, but when isDead == true; i don´t want to call NearCheckpoints() and i put in the IF statement a reference of isDead, but nothing happened, unity always move first the player to the near checkpoint and then call TakeDamage() that call PlayerIsDead()

    So, kind of shady but i think that the idea is there.
     
  2. martibergoglio

    martibergoglio

    Joined:
    May 28, 2015
    Posts:
    14
    So, after many tries i figured out that there is a real Inspector order execution so, problem resolved.
     
    theANMATOR2b likes this.