Hello. I have some issuses with update Text value of 3d text object.
For example: I create 3d text, qube and ball.
When i trow ball in qube and ball collides with qube i need update text of 3d text to “1”.
i trying many ways, but unity show 1 error.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class PointTracker : MonoBehaviour {
GameObject PointNum;
Text TextNum;
int CurrentPoints = 0;
// Use this for initialization
void Start () {
PointNum = GameObject.Find("PointNum");
TextNum = PointNum.GetComponent<Text>();
UpdatePoints(CurrentPoints);
}
// Update is called once per frame
void Update () {
}
public void UpdatePoints(int addNum)
{
CurrentPoints = CurrentPoints + addNum;
TextNum.text = "" + CurrentPoints;
}
}
And its
TextNum.text = "" + CurrentPoints;
Was creating error
NullReferenceException: Object reference not set to an instance of an object
PointTracker.UpdatePoints (Int32 addNum) (at Assets/Scripts/PointTracker.cs:27)
Please, help, what i doing wrong?