Search Unity

[solved] OnTriggerStay with specific GameObject

Discussion in 'Scripting' started by Kandrbol, Jul 1, 2019.

  1. Kandrbol

    Kandrbol

    Joined:
    Aug 15, 2018
    Posts:
    117
    This script has all GameObjects. But I want function Exit use only for exit from MyCar.

    What is wrong?

    private void OnTriggerExit(Collider other)
    {
    GameObject A = GameObject.Find("MyCar"); // It finded car. It is correct.

    if (other == A) // But here no function. Maybe I dont understand OnTriggerExit?
    {
    Debug.Log(10); // No write it.
    }
    }
     
  2. Vinayak-VC

    Vinayak-VC

    Joined:
    Apr 16, 2019
    Posts:
    60
    1. Check Both game objects has colliders
    2. Check Attached script game object is a trigger
    3. One of both objects has to rigidbody attached
    4. if its 2D then OnTriggerExit2D(Collider2D collision)

    has to be used
     
  3. Kandrbol

    Kandrbol

    Joined:
    Aug 15, 2018
    Posts:
    117
    I have it. This no function. But I create new script for OnTriggerStay and OnTriggerExit specific only for MyCar. This is simply solution....