Starting with Visual Studio and C#!

Matteo Lo Piccolo
3 min readApr 12, 2021

--

It’s time to setting the player position and create our first script!
First thing to do, ALWAYS, make project clean.
It’s really important, and make everything little bit easier to understand.
Right click on project window, create, folder, and name it Scripts.

Same thing to create our first C# script!
Right click on scripts folder, create, C# script and name it Player.

Now, we have to pay REALLY ATTENTION to the name of our script. Is important understand that the name we give to script have to be the same inside the compiler.

As you can see in the image, when highlight the C# script, in the inspector appear everythig we have write in that script.
If we look on the top, we read
public class Player : Monobehaviour
The important thing here is : the name Player is the same in the folder script and in th ecompiler.
If the name is different, Unity don’t recognize it and give us an error.
Pay attention to this!

This type of error can be happen, for example, when we create a C# script, but don’t give it a name.
If we rename it after, the name in the compiler DON’T CHANGE.
Look at example :

Create a C# script without rename

Now we change name, for example, NewScript.
Look at compiler

Change name of C# script in the folder to NewScript

You see?
The name in the compiler DON’T CHANGE, even if we rename it in the folder.
Watch out of this type of error.
There is a method to change name properly, and it is :
open compiler with double click on C# script, and that open Visual Studio Compiler (there are other compiler, but personally I always use Visual Studio, even though I used a compiler name Writer)

Visual studio can take a few minutes to open

If, if we look at name at top of the script. is NewScript, but in the compiler is NewBehaviourScript

To change it, highlight the name NewBehaviourScript, then left click.
Now hold CTRL and press two times R.
CTRL+R+R.

Now the name is the same at the top and in the compiler.

While this works “fine”, I highly recommend setting the right name in the beginning, to avoid problems.

--

--

Matteo Lo Piccolo
Matteo Lo Piccolo

Written by Matteo Lo Piccolo

Always in love with programming, even if late (I'm already 39 years old) I decided to follow my dream! We will see how far my passion will take me!

No responses yet