C# Variables with Unity

  • a scope (public, private, local)
  • a data type (int, float, bool, string)
  • a name
  • a value (optional)
private float _speed = 3.5f

Public, private or local variables

Data Types

int playerCount = 5;
float speed = 2.5f;
bool signOn = true;
string playerName = "Peter";

Naming your Variable

Example PascalCase for a public variable: MySpeed
Example camelCase for a private variable: _mySpeed
Example camelCase for a local variable: mySpeed
[SerializeField]
private float speed = 2.8f;

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andrea Zilio

Andrea Zilio

Passionate Game Developer and Learning Expert. I love to create games and interactive experiences using Unity, Articulate, C#, JavaScript, PHP, HTML, CSS.