Road TO Dev — Variables!

Rob Smith
2 min readMar 24, 2021

First what is a Variable? Well the basic definition when relating to code is it’s a container that holds information you want to use. There are many types of variables. The most common are Integer, Boolean, Float, and String.

Int is used when you want to represent a whole number only. Bool is when you want to have a yes/no toggle or on/off. Float is used when needing decimals and also in Unity needs to have f at the end. String is for using text.

You can also set a variable to be public or private. What this means is when set to public any script can access that variable which is good if you need to manipulate numbers on other objects using that specific variable. Private is so only that script can use it.

This also effects the codes display in the editor of Unity. If you set it to public you can see the code and manipulate it live as you work. When set to private you need to Serialize that variable in order to work with it on the editor. This is nice because you can keep it private and still have it be open in the editor.

Look at that structure! You first declare if you want the variable to be private or not, then you declare the type of variable it will be, and then you give it a name the name is up to you but should make sense and conform to the standards of the industry when you can.

Notice private gets _ in front. Also I set starting values for these but you don’t have to this can be declared later, but keep in mind numbers will default to 0.

--

--

Rob Smith

Hi there! I am currently on the path to learn how to become a unity developer and will be documenting my journey as best as I can here. Thanks for looking!