I am working on my Unity game and I tried to use "Debug.Log" to log the name of the object the player collided with, but when I tried it, it said that debug does not contain a definition for log. I compared my code to code that does work and they look pretty much the same. I don't know how to fix this.
Here's the code I used
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Debug : MonoBehaviour
{
void OnCollisionEnter (Collision collisionInfo)
{
Debug.Log(collisionInfo.collider.name);
}
}
Any ideas on why this didn't work?
Because your class has the same name as UnityEngine.Debug, and your class doesn't contain a Log method. Because you are working inside your class named Debug its trying to use the class over the Debug.Log from Unity
Try change the class name to something other than Debug.
public class TestClass : MonoBehaviour // CHANGED CLASS NAME
If you really want to keep the class name as Debug change this line
Debug.Log(collisionInfo.collider.name);
to this
UnityEngine.Debug.Log(collisionInfo.collider.name);
Hope this helps