I have created UI text object
And then created Text field in behavior class:
using UnityEngine.UI;
public class Explorer : MonoBehaviour
{
public Material mat;
public Text text;
...
void FixedUpdate () {
...
text.text = string.Format("x {0}", scale);
If I just run it, it says
Object reference not set to an instance of an object
at runtime.
If I try to drag ZoomText to Text slot, it doesn't allow me:
If I first drag ZoomText from Hierarchy to Project
then it allows me to set Text slot, but still gives
Object reference not set to an instance of an object
at runtime.
If I am trying to set text field by Find
private void Start()
{
text = (Text) GameObject.Find("ZoomText");
}
it gives me
Cannot convert type 'UnityEngine.GameObject' to 'UnityEngine.UI.Text'
What I am doing wrong? Suspect may be incorrect types, but how to know correct ones?



