Search Unity

OnTriggerExit called automatically after an OnTriggerEnter

Discussion in 'Physics' started by dienat, Aug 23, 2019.

  1. dienat

    dienat

    Joined:
    May 27, 2016
    Posts:
    308
    I have one object colliding with other, object A with rigidibody and iskinematic with nontrigger collider and object B with collider with istrigger

    On objecta A i have a script with the following code. The result is that when objects collide OnTriggerEnter calls automatically OnTriggerExit

    Code (CSharp):
    1.    
    2. private void OnTriggerEnter(Collider other)
    3.     {
    4.             if (other.GetComponent<ClassObjectB>())
    5.             {
    6.                 other.GetComponent<ClassObjectB>().collidingWithPlayer = true;
    7.             }
    8.     }
    9.  
    10.     private void OnTriggerExit(Collider other)
    11.     {
    12.             if (other.GetComponent<ClassObjectB>())
    13.             {
    14.                 other.GetComponent<ClassObjectB>().collidingWithPlayer = false;
    15.             }
    16.     }
    17.