How to get number of clicks and display numbers

I'm very new to unity and javascript so I'm having a hard time trying to figure out something. I am trying to get the number of user clicks when someone clicks a game object and then have it display on the screen how many times they clicked the item. I'm guessing I would use GUIText to display it?

Thank you for any help.

A label would work too.

You would need a collider on the object. Set to Is Trigger, then use OnMouseDown to increment the counter. In the OnGUI routine, show that counter in that label.

If that's not working, you may want to Raycast it. You'd convert the current mouse position in screen coords to a ray and see what it hit (or alternately, check the object in question for such a hit). Then increment the counter when hits are detected.

I'd write the code for you, but it's all in pieces in the scripting reference.

Am I on the right track? I keep getting errors

`function counter() { var starCount = 0; var mushroomCount = 0; var coinCount = 0; }

function OnGUI() { GUI.Label(Rect (0, 10, 400, 20), "You have"); //GUI.Label(Rect(50, 10, 400, 20), counter.write(starCount)); this is where I'm trying to write the number of clicks.

GUI.Label(Rect (100, 10, 400, 20), "Mushrooms");
GUI.Label(Rect (0, 30, 400, 20), "You have");
GUI.Label(Rect (100, 30, 400, 20), "Stars");
GUI.Label(Rect (0, 50, 400, 20), "You have");
GUI.Label(Rect (100, 50, 400, 20), "Coins");
}

function OnMouseDown() { if(!collider.isTrigger) { counter.starCount++; } }

`