Search Unity

IF and ELSE IF both true at the same time??

Discussion in 'Scripting' started by asdfasdf234, May 26, 2017.

  1. asdfasdf234

    asdfasdf234

    Joined:
    Nov 27, 2015
    Posts:
    76
    I attached this code to a child of some GameObject, what the code is doing is just checking if the collision happens between child and parent (that is what it should do, but it doesnt work ??).

    Code (CSharp):
    1.     private void OnTriggerStay(Collider other)
    2.     {
    3.         if( other.gameObject.GetInstanceID() == transform.parent.gameObject.GetInstanceID())
    4.         {
    5.             Debug.Log("other gameobject instance ID: " + other.gameObject.GetInstanceID());
    6.         }
    7.         else if (other.gameObject.GetInstanceID() != transform.parent.gameObject.GetInstanceID())
    8.         {
    9.             Debug.Log("this gamobject instance ID: " + transform.parent.gameObject.GetInstanceID());
    10.         }
    11.        
    12.     }
     
  2. asdfasdf234

    asdfasdf234

    Joined:
    Nov 27, 2015
    Posts:
    76
    Never mind, figured it out, I had 2 same looking but different gameobject at same place, didn't see it before because I have very messy hierarchy :=(