Basics of C# Variables!

Jacob Jones
3 min readJun 12, 2021

Make sure to use a Semicolon (;) at the end of every line of code!

When it comes to variables like strings, bools, int and floats, you can decide whether they are public or private. If you make a variable public, everyone has the ability to access it. You can also see your variable in the inspector window of Unity when you use the public option! See the below image for an example. When you are naming your variable, remember to use proper camel casing! Camel case is used when writing code, you will always capitalize the first letter of every word after the first initial word.

Ex. thisIsAnExampleOfHowToUseCamelCase

Inspector view after using a public variable!

When using the private option, that variable will stay only within the script you made it in! Keep in mind that by doing this it will stay hidden, meaning it will not be in your inspector tab of Unity!

Now lets break down the different types of variables starting with a string! When you use a string, the code will then expect characters of text or letters. So a string = ABCDEFG

Next, lets go over what a bool is! Bool is just another simple variable, this one means true or false. If your character in a game cannot enter a locked door, you may use a bool to say, has key = false. Once your your character has the proper key, then you can have it say true and give them access to the door!

Only a couple more to learn! This time we will talk about int! This is short for integer. When using this variable, your telling your code that you will be using numbers!

Finally! You have made it to the last variable, a float! A float is to identify that a number is a decimal. When using this, always put an “f” at the end of the number to signify that it is a float. So remember, when using a float, press F to pay respect!

Congratulations! You now know the basics of variables! Now you can continue onto your journey as a game developer!

--

--