Error when using Debug.Log() Command

Hi, for some reason when I try to add the Debug.Log() Command I get an error -

Why is that and How can I solve this?

Thanks!
Noam

1 Like

Also, when I type void OnCollisionEnter2D() in VSC I don’t get an autocompleted answer.
I Installed NET Framework 4.7.1 but it doesn’t solve this issue.

How can I address this?

Hi,

All errors must be fixed. Otherwise, IntelliSense cannot work properly. Make sure there are no superfluous curly brackets. Remember you can also look at the lecture code changes via the link in the Resources of each lecture.

If all errors are fixed, is Visual Studio Code selected as your External Script Editor in Unity (Edit > Preferences > External Tools)? If so, please follow the instruction on this website and make sure all required extensions are installed: https://code.visualstudio.com/docs/other/unity

Did this help you fix the issue?


See also:

You have one too many ending-curly bracket…

(two opening-curly brackets, but three ending-curly brackets)

1 Like

Hi, even after removing the extra ending curly brackets, the error remains.
I have the C# extension installed on my VS I tried the others on the list but they didn’t really make any difference.

Is there another solution?

Thanks for the reply, but it didn’t help :frowning:

You removed too many of them…

You went from 2 opening and 3 closing brackets, to 1 opening and 1 closing backet… You need 2 and 2…

These things come in pair: you need one pair for the class, and one pair for the method… you’re missing the pair for the method:

public class Collision : MonoBehaviour
{
  void OnCollisionEnter2D(Collision2D other)
  {
    Debug.Log("Ouch");
  }
}

also you spelt OnCollisionEnter2D wrong…

Thanks for the answer but please take in mind that I am just starting out and English is not my first language…

A more understanding tone towards people who are just starting to learn something challenging and new
is just the thing that encourages or discourages from trying again.

apologies, did I say something in the wrong tone?

Anyway: if you try to get the brackets correct first, so have { } at beginning and the end of the class, then { } at the beginning and the end of the method, the intellisense should be a great help to guide you as to spell things and the likes. Alternatively, there is the Unity documentation that could help where you can copy and paste to make sure you have it correctly set up. In your particular context, here is the one you need that might be of help:

That was probably a misunderstanding, @endlessblink. Describing code is not easy. @solofo just tried to help you. :slight_smile:

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture? You could compare the number and positions of your curly brackets to Rick’s.

Try adding this - using Debug = UnityEngine.Debug;
I had to place Debug manually under the using* for the errors to go away.
Like so -

line 1) using System.Diagnostics;

line 2) using System.Collections;

line 3) using System.Collections.Generic;

line 4) using UnityEngine;

line 5) using Debug = UnityEngine.Debug;

1 Like

guess I misunderstood. Thanks for the additional info!

Yes, I guess it was just a misunderstanding on my part. Solofo’s tips helped me figure it out.

1 Like

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

Privacy & Terms