Search⌘ K
AI Features

Variables

Explore the fundamentals of variables in C# within Unity, including how to declare, initialize, and use them. Understand the importance of variable scope and access levels such as public and private. This knowledge helps you write clear and organized scripts to control behaviors in your AR projects effectively.

Introduction

In Unity, variables are used to store values that can be used and manipulated by our ...

C#
int score; // here, 'int' is the data type and 'score' is the name
float speed; // here, 'float' is the data type and 'speed' is the name
string playerName; // here, 'string' is the data type and 'playerName' is the name
bool isJumping; // here, 'bool' is the data type and 'isJumping' is the name

Initializing variables

Variables can be initialized with a value when they are declared. An example is given below:

C#
int score = 0;
float speed = 10.0f;
string playerName = "Player1";
bool isJumping = false;

Using variables

...