Hello,
I am following the beginner tutorial named Roll-a-Ball ( found here: http://unity3d.com/learn/tutorials/projects/roll-a-ball/displaying-text) 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
inspector.
PlayerController.SetCountText () (at
Assets/Scripts/PlayerController.cs:40)PlayerController.OnTriggerEnter
(UnityEngine.Collider other) (at
Assets/Scripts/PlayerController.cs:34)
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);
}
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
void SetCountText ()
{
countText.text = "Count: " + count.ToString ();
}
}