From ETC Public Wiki
Jump to: navigation, search

Min Function


Max Function


Mod Function

 num = (num + 1) % maxNum;

Using min and max to keep a value within a range

 var result : int = Mathf.Max(minValue, Mathf.Min( value, maxValue));

Div Function

 var div : int = float / n; 

since div is of type int no type cast is needed.

int division for health bar

 barLength = (1.0 * health / maxHealth) * barMaxLength;

Random numbers


static function Range (min : float, max : float) : float

static function Range (min : int, max : int) : int

Both min and max are included in the range of possible numbers


static var value : float

 // Prints something between 0 and 1
 // Loads a random level from the level list
 Application.LoadLevel(Random.Range(0, Application.levelCount));

Distance between two objects

 var other : Transform; 
 var dist = Vector3.Distance(other.position, transform.position);