I am a beginner in unity and I am having a problem with how to do the OnCollisionExit
in OnControllerColliderHit
. What I want to do is to detect the collision and make the object appear by setting the SetActive
to true and then setting the SetActive
to false to make it disappear again upon exiting the collision or contact with the object. Generally, I just want to know how to do the OnCollisionEnter
and OnCollisionExit
when using OnControllerColliderHit
.
Here is my code: using UnityEngine;
public class PlayerCollision : MonoBehaviour
{
public PlayerMovement movement;
[SerializeField] GameObject _toggleObject;
private void OnControllerColliderHit(ControllerColliderHit hit) {
if(hit.gameObject.tag == "Obstacle")
{
_toggleObject.SetActive(true);
}else
{
_toggleObject.SetActive(false);
}
}