Game Development Reference
In-Depth Information
Type names
A couple of the basic types are spelt differently in pure Unity C#. In JavaScript, we use
Boolean
and
String
, but in pure Unity C#, we use
bool
and
string
.
JavaScript:
var isHit : Boolean;
var myName : String;
C#:
bool isHit;
string myName;
However, there is an excepion. If you include
System
in your C# script, you will be able to
use
String
and
Boolean
classes (the upper-case) of
.NET
, similar to the following script:
C#:
using System;
Boolean isHit;
String myName;
Variable declaration
Variable declaraion is diferent, including access and type speciicaion.
JavaScript: The type speciicaion is not necessary.
public var playerLife = 1; // a public var
int playerLife = 2; // **private** access is default
public GameObject myObj; // a type is specified (no value
assigned)
C#: The type is always stated when declaring a variable.
var playerLife = 1; // **public** access is default
private var playerLife = 2; // a private var
var myObj : GameObject; // a type is specified (no value
assigned)