How to display score count in game?


I am following the beginner tutorial named Roll-a-Ball ( found here: and I have ran into a problem when I try to display the score count in the game.

The game tutorial was made with a GUI Text component and from my understanding, the GUI reference is now a legacy reference. The new reference is UI and I can only add a UI Text component.

I have added a UI Text component and typed the code that keeps track of the score under the player component as dictated in the video. The code can be found below. When I try to associate a reference to my Count Text property in the Inspector window, Unity does not allow me to do it. I think that this is because I am not using a GUI Text component.

Could anyone help figure out how to add a reference to the Count Text property? Here is the error:

UnassignedReferenceException: The
variable countText of PlayerController
has not been assigned. You probably
need to assign the countText variable
of the PlayerController script in the
PlayerController.SetCountText () (at
(UnityEngine.Collider other) (at

  using UnityEngine;
using System.Collections;
    public class PlayerController : MonoBehaviour 
    	public float speed;
    	private int count;
    	public GUIText countText;
    	void Start ()
    		count = 0;
    		SetCountText ();
    	void FixedUpdate()
    		float moveHorizontal = Input.GetAxis("Horizontal");
    		float moveVertical = Input.GetAxis("Vertical");
    		Vector3 movement = new Vector3 (moveHorizontal,0.0f,moveVertical);
    		rigidbody.AddForce(movement * speed * Time.deltaTime);
    	void OnTriggerEnter(Collider other)
    		if(other.gameObject.tag == "PickUp")
    		other.gameObject.SetActive (false);
    		count = count + 1;
    		SetCountText ();
    	void SetCountText ()
    		countText.text = "Count: " + count.ToString ();

There’s a gamer/programmer whose username is quill18 (quill 18) and he made a pretty neat tutorial on scoreboards, external link: Unity 3d Tutorial: Making a Scoreboard #1 - YouTube

He has other tutorials in which he ceates complete videogames, and most of those have score displaying. External link to his YouTube channel: quill18creates - YouTube

Got irritated enough to redo the video, enjoy.

Original Answer

Tutorial is out of date. This question has been asked before gui text is absent in Unity 4.6 - Unity Answers.

In short the answer is add using UnityEngine.UI; to the top of your script, and change the variable type from GUIText to Text. A complete script is available here.