问题
Im trying to show on console when a gameobject collides with another gameobject with collide. I keep getting this error on unity's console ERROR CS0117, 'Debug' does not contain a definition for 'log'.
- im on mac using .net core
- im using vs code 1.35.1 and unity 2019.3.0a5
- i already have all the usings that i need, but intellisense does not find a definition for my debug or for anything whatsoever, this is frustrating :/
i dont have any other .cs file named debug neither
using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.SceneManagement; public class DeadZone : MonoBehaviour { private void OnCollisionEnter2D(Collision2D collision){ Debug.log("Collision"); } private void OnTriggerEnter2D(Collider2D collision){ Debug.log("Trigger"); } }
i expect a "collision" message in the console of unity when my ball gameobject touches a wall gameobject, both with collider but i only get that error within the console, i also already tried using UnityEngine.Debug.log(); but havent got any success yet... :(
回答1:
You are using Debug.log()
. but you should be using Debug.Log()
. Notice the capitalised "L" on "Log".
By naming convention for C# method names will always start with a capital letter.
If you look at the Unity Docs for Debug.Log you'll also see in the code examples/title that it uses the capital L
Also judging from your tags you are using Visual Studio. Make sure that intelliSense is turned on, as this should detect and most of the time even automatically fix these kinds of typos for you.
来源:https://stackoverflow.com/questions/56679450/error-cs0117-debug-does-not-contain-a-definition-for-log