- Home /
This question was
closed Oct 26, 2015 at 05:14 PM by
replay55 for the following reason:
The question is answered, right answer was accepted
Question by
replay55 · Oct 22, 2015 at 08:02 PM ·
staticobject referenceobject-reference-error
Object Reference
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TextHints : MonoBehaviour {
Text text;
public float timer = 0.0f;
// Use this for initialization
void Start () {
text = GetComponent<Text>();
}
// Update is called once per frame
void Update () {
if (text.enabled) {
timer += Time.deltaTime;
}
if (timer >= 4) {
text.enabled = false;
timer = 0.0f;
}
}
void ShowHint(string message){
Text.text = message;
if(!Text.enabled){
Text.enabled = true;
}
}
Here's my code. I have errors on lines 24, 25, 26, saying I need an object reference. What is an object reference? I've looked up other solutions, but changing things to GameObjects doesn't work, unfortunately.
Comment
Answer by Jessespike · Oct 22, 2015 at 08:24 PM
Try this:
text.text = message;
if(!text.enabled){
text.enabled = true;
"text" is your object reference. "Text" is a class.
Follow this Question
Related Questions
How do I fix this error 0 Answers
ERROR - An object reference is required to access non-static member 3 Answers
FSM object reference not set to an instance of an object 0 Answers
C# script for calculating the distance between the player and objects 1 Answer
Is it possible to define a public variable of type UnityEngine.Object? 0 Answers