Question by
QuestionText · Jun 26, 2016 at 06:02 AM ·
c#textupdate3d text
3d Text update. How its work?
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?
Comment
Answer by JedBeryll · Jun 26, 2016 at 06:23 AM
If it's a 3D text then it's not a "Text" but a "TextMesh".
TextNum = PointNum.GetComponent();
Your answer
Follow this Question
Related Questions
Message Centre Does Not Display 0 Answers
Removing an item from Inventory and updating item count on HUD 0 Answers
Issuse with 3d Text Update or couple months thinking about error. How its works? 1 Answer
How to restrict user from typing certain numbers in input field 3 Answers
Health system in a text based game. 2 Answers