Search Unity

Question OnTriggerEnter is not working and not triggering.

Discussion in 'Physics' started by SharonL75, Sep 9, 2020.

  1. SharonL75

    SharonL75

    Joined:
    Aug 13, 2020
    Posts:
    91
    I have a Carte ion the scene :
    The Carte have a box collider :

    upload_2020-9-9_10-48-47.png

    And I have a Player the Player have some components : Also Animaitor , Rigidbody

    upload_2020-9-9_10-49-45.png

    And the script that attached to the Player :

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class UnlockCrate : MonoBehaviour
    7. {
    8.     public GameObject player;
    9.  
    10.     private void OnTriggerEnter(Collider other)
    11.     {
    12.         if(other.name.Contains("Crate"))
    13.         {
    14.             Debug.Log("Hit !");
    15.         }
    16.     }
    17. }
    18.  
    First the script was attached to the Carte but then I moved it to the Player.

    In any case the trigger is not working , it does working if for example I set on the Player the Capsule Collider Is Trigger to true but then the Player is falling down or walk through objects and if I set the TRigidbody Is Kinematic to true then the Player will not move it will walk on the place.

    The main goal is when the Player is getting close enough to the Carte then play animation. but the trigger part is not working.
     
  2. MuzaibRanjha

    MuzaibRanjha

    Joined:
    Aug 28, 2017
    Posts:
    6
    your Crate collider is not triggered