Unity OnCollisionEnter function not registering

362 views Asked by At

I am not able to register my OnCollisionEnter(); I have copied the function from a previous Unity program that works and replicated everything. The collision between the FPSController should be lowering the TreeHealth.

enter image description here enter image description here

    void OnCollisionEnter(Collision collision)
    {
        print("Colision");
        if (collision.gameObject.tag == "TreeTag")
        {
            treeScript = collision.gameObject.GetComponent<TreeFall>();
            treeScript.treeHealth--;
        }
    }
2

There are 2 answers

1
SushiWaUmai On BEST ANSWER

Did you try to use OnControllerColliderHit? I think you have to use this method instead of OnCollisionEnter if you move the character with the CharacterController Component.

1
Omer Ozhan On

I would recommend you to replace the print() function with Debug.Log() and detecting collisions in the tree script and check for collisions from the player.