Debug.Log();

Hey I’m having some trouble. The way that Debug.Log(); is shown in the Delivery Driver 2d game wasn’t working for me the way it was taught.

All brackets are in the right place. Debug.Log(); by itself was giving me an error, and someone made the recommendation to put - Using System.Diagnostics; on line 1, and - Using Debug = UnityEngine.Debug; on line 5. That made it work but the course said nothing about it. Has VSCode or Unity changed since the course was made?

Having a hard time understanding those elements since it wasn’t mentioned.

That will work but it’s completely unnecessary. You can remove using System.Diagnostics; completely. It just confuses things and we never use it. Once you’ve done that there is no need for using Debug = UnityEngine.Debug; (you can just change it back to using UnityEngine;) and everything will work the way it does in the course.

Here’s what’s happening: Both System.Diagnostics and UnityEngine has a type called Debug. When you have both in the using section, the compiler does not know which of these types you want to use. The recommendation is to ‘alias’ the UnityEngine.Debug to just be Debug so the compiler will know which one to use (because it uses the alias) but in 99% of games we never need System.Diagnostics so it does not need to be in the using list at all.

You will find the same problem when you start using Random because System and UnityEngine also both have a type called Random and when you need to use stuff from System (like Serializable) and you want to also get random values from UnityEngine.Random you will find the same error happening. In this case I personally alias Random (using Random = UnityEngine.Random;) but you could just qualify the types you want to use, like System.Serializable instead of just Serializable and then not have the using System; in the using section.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms