Variable and Debug

Why can’t I define the variable rb like this?

And why can’t I use Debug without UnityEngine in front of it?

You cannot call a non-static method (like GetComponent) in a field initialiser. It has to be called from within a method (like Start). Also, you defined it as int which wouldn’t have worked anyway

Because you have using System.Diagnostics; at the top. System.Diagnostics also has a Debug class. Just remove that line and you’ll be fine

1 Like

Thank you for your knowledge

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

Privacy & Terms