Videogames Development – Unity – OnClick Counter
A great snippet if you make a game that needs a click counter!
Code:
#pragma strict function Start () { } // On Click Counter START ######################### //This is the variable we are using to store the number of clicks var clickCounter: int; //This creates a button and adds +1 to clickCounter variable every 1 click function OnGUI () { if (GUI.Button (Rect (10,10,150,100), "You clicked:" + clickCounter)) { clickCounter ++; } } // On Click Counter END ########################### function Update () { }