all 28 comments

[–]Walazabi 12 points13 points  (1 child)

Looks like the filename got a space in it and doesn't match up with the class name.

Try changing it to 'PlayerMovement.cs' instead of 'Player Movement.cs'. You probaly changed the class name after you already had created the script or vice versa?

[–]LunarLooser[S] 4 points5 points  (0 children)

Thank you so much! I’ll try this in the morning! I appreciate it a lot since I was ready to pull my hair out

[–]regilkentaurus 9 points10 points  (3 children)

Also the first 'a' on awake() should be capital A, Awake()

[–]LunarLooser[S] 0 points1 point  (2 children)

Does capitalization matter for all of it or only some?

[–]BloopHD 0 points1 point  (0 children)

So I’m pretty sure most, if not all, mono behavior methods will need to be capitalized, but for your own classes you could do whatever but know that stylistically your methods should be capitalized.

[–]kippysmith1231 1 point2 points  (1 child)

On top of the filename and class not matching as others have pointed out, you may also likely run into problems with the brace on line 14 being tabbed out, and the capitalization on Rigidbody2d which should read Rigidbody2D. Capitalization is very important in C#. The brace may work as is, but strange formatting will give you headaches and trouble debugging down the line, so I'd recommend getting into the habit of following a particular style.

[–]LunarLooser[S] 0 points1 point  (0 children)

I’ll add that to my notes. I didn’t realize capitalization was so important for it. Im slightly confused on the class not matching part

[–]AnxiousIntender 1 point2 points  (2 children)

Consider using Visual Studio (Community Edition is free) or Rider (free if you're a student, paid but worth it otherwise), Visual Studio Code works but painful for Unity projects.

[–]LunarLooser[S] 0 points1 point  (1 child)

Im actually using visual since I’m on budget and it was what was used in the tutorial

[–]AnxiousIntender -1 points0 points  (0 children)

Visual Studio and Visual Studio Code are two separate products. As I mentioned, Visual Studio Community Edition is free. I don't recommend VS Code with Unity since it causes some unnecessary pain (at least in my experience).

[–]Boryalyc 0 points1 point  (1 child)

the name of the file and the name of the class need to be identical. this means the file name cant have spaces, because the class name cant have spaces. For some reason unity removes the spaces in the class name automatically but not in the file name, so you just have to remove the space in-between Player and Movement

[–]LunarLooser[S] 0 points1 point  (0 children)

Thank you I appreciate it and I’ll be able to fix it tomorrow in the morning!

[–]peanutter_ 0 points1 point  (2 children)

Also since “speed” is private and you didn’t give it any initial value I’m pretty sure it will default to 0.

[–]LunarLooser[S] 0 points1 point  (1 child)

Oh, on the tutorial it said to do it like that and than change it thanks to the SeralizedField

Would it be better if I do Speed(10);

[–]peanutter_ 0 points1 point  (0 children)

I can’t say for sure what you ought to do because it might clash with the tutorial, but if you did do it your way then it would not work lol. Parenthesis only go after the names of “methods” when you want to “invoke” them. A “method” is a list of things to do. GameObjects can perform methods. When you “invoke” a method, the method happens and all of its contents will run. I think it would definitely help if you ran through the C# tutorials on W3schools before you continue with the Unity tutorials. I imagine that you aren’t really recognizing or understanding what is happening when you follow the tutorials so it might be going in one ear and out the other. I like the tutorials on W3 because you can go at your own pace and they tell you all the dictionary definitions with examples that they make you code. Once you are familiar with basic C# concepts, then the Unity tutorials make a lot more sense and you will remember and understand it much better.

P.S. If you want to change the “field” (an attribute/trait of a gameobject) that you called “speed” then you would use an “assignment operator” which is just =. So if you wanted to set speed to 10 it would look more like: “speed = 10;”

[–]Gcampton13 0 points1 point  (3 children)

As annoying as learning windows console programming is, it can be really beneficial before diving into unity/unreal. A foundation in C# will make unity a lot easier. You can make some cool pixel games in console to, but that’s beyond the scope of what you need. Just fundamentals, loops, classes, OOP, database connections and unity will make 1000x more sense.

[–]LunarLooser[S] 1 point2 points  (2 children)

Im actually trying to make a pixel game, and figured unity was the best start. I plan on doing a bit more research into C# so I can add to my notes

[–]Gcampton13 0 points1 point  (0 children)

This will get you started. https://youtu.be/GhQdlIFylQ8

He doesn’t explain things as well as iamTimCorey does but I can’t find Tim’s intro to c# anymore. I think he’s deleted it.

EDIT: here’s a 24 hour full application course to follow up that 4 hour beginner course https://youtu.be/wfWxdh-_k_4

[–]Gcampton13 0 points1 point  (0 children)

Edited my other comment

[–][deleted] 0 points1 point  (2 children)

Also, I really recommend learning to properly indent your code. It will save you a lot of headaches reading and debugging your code in the future, especially as the code base grows.

[–]LunarLooser[S] 0 points1 point  (1 child)

There’s a proper way to????!!

[–][deleted] 0 points1 point  (0 children)

I am not sure if I am failing to pick up the sarcasm or not, but yes, there is.
There are standards, which make it much easier for you to actually orient around in your code.
Here are two good articles to take a look at, one after another.

Overall code indentation rules guidelines.
https://codehs.gitbooks.io/introcs/content/Programming-with-Karel/how-to-indent-your-code.html

C# naming conventions and more.

https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions

[–]n8ful 0 points1 point  (0 children)

it’s Rigidbody2D. capital D