Skip to Content
Learning C# by Developing Games with Unity 3D Beginner's Guide
book

Learning C# by Developing Games with Unity 3D Beginner's Guide

by Terry Norton
September 2013
Beginner content levelBeginner
292 pages
6h 19m
English
Packt Publishing
Content preview from Learning C# by Developing Games with Unity 3D Beginner's Guide

Declaring a variable and its type

Every variable we want to use in a script must be declared in a statement. What does that mean? Well, before Unity can use a variable; we have to tell Unity about it first. Ok then, what are we supposed to tell Unity about the variable?

There are only three absolute requirements for declaring a variable and they are as follows:

  • We have to specify the type of data a variable can store
  • We have to provide a name for the variable
  • We have to end the declaration statement with a semi-colon

The following is the syntax we use for declaring a variable:

typeOfData nameOfTheVariable;

Let's use one of the LearningScript variables as an example; the following is how to declare a variable with the bare minimum requirements:

int ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning C# by Developing Games with Unity 2019 - Fourth Edition

Learning C# by Developing Games with Unity 2019 - Fourth Edition

Harrison Ferrone
Unity 3D Game Development

Unity 3D Game Development

Anthony Davis, Travis Baptiste, Russell Craig, Ryan Stunkel

Publisher Resources

ISBN: 9781849696586Other