I am writing a script that shows a collision between one object and an obstacle. The code runs but does not output within the console. Is there something that I am doing wrong?
using UnityEngine;
public class collision : MonoBehaviour{
void OnConllisionEnter (Collision collisionInfo)
{
if(collisionInfo.collider.tag == "Obstacle")
{
Debug.Log("We Hit an obstacle!");
}
}
}
I added a tag to the object as I will be adding more obstacles to simplify the process. I checked for semicolons and any other errors that would stand out to me. I am not sure what I am supposed to change or if I am missing something.
CodePudding user response:
You actually have a typo in the methods name
// Here
// |
// v
void OnConllisionEnter (Collision collisionInfo)
The code should be
using UnityEngine;
public class collision : MonoBehaviour{
void OnCollisionEnter (Collision collisionInfo)
{
if(collisionInfo.collider.tag == "Obstacle")
{
Debug.Log("We Hit an obstacle!");
}
}
}