Updating GUI text with GetButtonDown?

Hi

Firstly, apologies if the answer to this question already exists, following 2 hours of searching I am drawing a blank - and its likely down to minimal coding experience and not spotting the gem of a script that’d do the job. I really do appreciate any help and advice of any kind.

So, what I am trying to achieve is an update to some GUI text each time the player clicks the left mouse button. My game involves volleying a soccer ball - and I essentially want this displayed as a score via GUI text.

I have a GUI Text GameObject - which is numerical and starts at 0. Each time I click (the input for keeping the ball up) i’d like this text to increment and update. Here is what I am trying to do…and its most likely I am trying to reinvent the wheel and completely failing in my logic:

var guiText : GUIText;
    
var clickCount : float= 0;
    
    function Update() {
    
    if(Input.GetButtonDown("Fire1"))
    
    	{
    
    		guiText.text = clickCount++;
    
    	}
    
    }

The error I currently get after assigning the script to the Gui Text (value) is:

Assets/GuiCounter.js(7,17): BCE0004: Ambiguous reference ‘guiText’: GuiCounter.guiText, UnityEngine.Component.guiText.

Any advice would be awesome. I see where the error is, just haven’t got a clue where to go with it. My simple mind tells me this should work but its obviously completely wrong. Please don’t laugh too hard…

guiText is the name of a property - Component.guiText, as the message error inform - but you created a variable with this same name. If this script is attached to the GUIText object, just remove the variable declaration at the beginning and you will use the property directly. If it’s attached to other object, change the variable name to anything but guiText (GuiText, gText, myGuiText etc.)