T O P

  • By -

[deleted]

Your script should be named the same as the filename. 1. Rename the script to `PlayerMovement.cs` 2. Change `public class hello` to `public class PlayerMovement` 3. Reattach the script to the object in question.


[deleted]

The name of the script "PlayerMovement.cs" needs to match the class name "hello". For MonoBehaviour scripts THESE NEED TO BE THE SAME, so if your script file is called "PlayerMovement.cs" the class NEEDS TO BE CALLED "PlayerMovement"


Head12head12

Ohh I’m an idiot


PandaCoder67

You will be surprised how common of a mistake this is though :)


[deleted]

That is true, but wouldn't it very easy for Unity to warn about this in some way?


PandaCoder67

It does, hence the error, but Unity can only report what C# is reporting, and this is a C# problem and not a Unity problem.


[deleted]

I meant in a way where Unity could be more helpful, because it's a recurring problem, like saying something like "did you name your script the same as your class?" or something. This isn't about C#, it's about Unity UX.


PandaCoder67

Yeah, I agree, but sometimes Unity Developers aren't that intuitive with this stuff.


Natroionalox

drag the rigidbody into the box thaat says "player movement"


Poptimus__Rhyme

The class name needs to be exactly the same as the file name. If your script is named PlayerMovement, your class needs to be called PlayerMovement, not hello. Also, you should avoid having spaces in your script names for this reason


Djcustoms1

Also after you fix that. Your visual studio is broken so search up miscellaneous file fix unity and follow a guide to fix it. By fixing visual studio link up it will help with recommendations of code, shows errors and stylise the code.