M.Nouri
M.Nouri

Reputation: 23

OnCollisionEnter not detecting

I am trying to make the game go to Dead scene when collided by does not work. And it even does not detect the collsion.

I've attached the script to empty game object that has box collider with is trigger ticked and the player does have a Rigidbody too.

I am not sure what is wrong, please help.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Health : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }

    public void OnCollisionEnter(Collision collision)
    {
        Debug.Log("dead without if statement");
        if (collision.gameObject.tag == "Player")
        {
            Debug.Log("Dead Mate");
            SceneManager.LoadScene("DeadScreen");
        }
    }
}

Upvotes: 2

Views: 997

Answers (1)

Ausländer
Ausländer

Reputation: 499

"I've attached the script to empty game object that has box collider with is trigger ticked and the player does have a Rigidbody too." If i understand you correct you enabled trigger on box collider if yes you must implement

    void OnTriggerEnter(Collider col)
    {

    }

Not

    public void OnCollisionEnter(Collision collision)
    {

    }

Upvotes: 1

Related Questions