Counter of clicks after gui.button pressed

Hi, Im trying a RTS game. I use gui.button to select type of soldiers and spawn it in map, each click on map spawns one soldier.

I need to counter that clicks to control how many soldiers have been spawned.

I can’t find nothing, someone can help me?

Thanks in advance :wink:

   var i : int = 0;

   function OnGUI() 
   {     
        if (GUI.Button(Rect(10,10,50,50),btnTexture))
        {
         i += 1;
        }
    }

This should count each click on the button and store the number in “i”.

Maybe you don’t understand me :slight_smile:

I did with :

if(Input.GetMouseButtonDown(0))
{
     cont++;
}