Question by
QuestionText · Jun 26, 2016 at 12:25 AM ·
textupdate3dtext3d text
Issuse with 3d Text Update or couple months thinking about error. How its works?
Hello! I cant slove 1 error with 3d text. I see many YouTube video and for uploaders of video its works, but with my projects its dont work... Here my Update script. i just call that script from another to update text value .
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 string
TextNum.text = "" + CurrentPoints;
Call that error:
NullReferenceException: Object reference not set to an instance of an object
PointTracker.UpdatePoints (Int32 addNum) (at Assets/Scripts/PointTracker.cs:27)
Please help me and say what i am doing wrong... Thanks.
Comment
Best Answer
Answer by QuestionText · Jun 26, 2016 at 12:56 AM
WOOOOOHO! I slove it, just change
TextNum = PointNum.GetComponent<Text>();
to
TextNum = PointNum.GetComponent<TextMesh>();
and change declare TextNum from Text to TextMesh and all work!
I some people will need that slove in future.