Gui text

Does anyone know how to solve this problem?

Assets/Scripts/CoinCounter.cs(12,25): error CS0120: An object reference is required to access non-static member `UnityEngine.GUIText.text’

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class CoinCounter : MonoBehaviour
{
    public int coinCount = 0;
   
    // Update is called once per frame
    void Update ()
    {
        GUIText.text = "x" + coinCount;
    }
}

I can’t figure out why it is giving me this error.

GUIText is the name of a class, not a reference to an object.

If you’re using GUI Text, add a public variable:

public GUIText guiText;

and assign it in the inspector. Then change the line to:

guiText.text = "x" + coinCount;

If you’re using the new Unity UI, use “Text” instead to refer to a Unity UI Text element.

(If you don’t want to assign it in the inspector, you may be able to use GetComponent().)

Text is working, but there is a new issue:

NullReferenceException: Object reference not set to an instance of an object
CoinCounter.Update () (at Assets/Scripts/CoinCounter.cs:12)

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class CoinCounter : MonoBehaviour
{
    public int coinCount = 0;
    Text text;
    // Update is called once per frame
    void Update ()
    {
        text.text = "x" + coinCount;
    }
}

You should do the Unity tutorials before trying this. This is basic programming and is explained in detail in the tutorials.

Change line 8 to: **public Text text;**

Then assign the Text field in the inspector.

These will be very helpful to you: Learn game development w/ Unity | Courses & tutorials in game design, VR, AR, & Real-time 3D | Unity Learn