# How to add a UI Text for keeping Score in Unity 5

My Problem is simple I want to show scores on my game. The examples on internet are good but in Unity 5 there are no GUI elements but instead these are now UI elements. I was following this example: https://unity3d.com/learn/tutorials/projects/space-shooter/counting-points but it didn't work.
I followed the code and added a new UI text to the scene as in the picture. After adding the script to a .cs file and declaring public GUIText scoreText; and making this text as prefab when I drag it to the inspector panel it didn't get attached.

and it gave this error:

The variable scoreText of Fruits has not been assigned.
You probably need to assign the scoreText variable of the Fruits script in the inspector.


Fruit is a projectile and every time this projectile hits the container it should add the score. So how to do this in Unity 5. I've seen in one example online that on previous versions of unity there was this option of adding GUI Text in GameObject.

I got the same problem, try this instead of using public GUIText scoreText;

Put using UnityEngine.UI; at the top of your .cs file and after that change the variable type from GUIText to just Text like this:

public Text scoreText;

Complete code for better example:

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

public class GameController : MonoBehaviour
{
public Text scoreText;

// Use this for initialization
void Start () {

}
}


That should works fine.

Dragging the prefab file over gives it a reference to the prefab, not the actual instantiated version you've got in your scene.

If you drag the text box over from the scene itself, you should have no problem. You will see something like "GUIText" appear in Score Text instead of "None".