Question by
HorizonHD · Mar 31, 2016 at 03:32 AM ·
errorerror messagenullreferenceexception
Keep Getting NullReferenceException: Object reference not set to an instance of an object
this is super annoying and I cant seem to understand why im getting it, someone explain it please?
Heres the line that gives me the error;
txtDate.text = DateNumber.ToString("0");
and heres the whole script;
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class CalanderScript : MonoBehaviour {
public Text txtDate;
private float DateNumber;
public int CapValue;
public int TimeValue;
void Start () {
txtDate = GetComponent<Text>();
DateNumber = 1;
}
// Update is called once per frame
void Update()
{
DateNumber += Time.deltaTime / TimeValue;
txtDate.text = DateNumber.ToString("0");
if (DateNumber >= CapValue)
{
DateNumber = 1;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Array of dictionaries: "Object reference not set to an instance of an object" 0 Answers
Object reference not set to an instance of an object [HELP!] 0 Answers
Multiple .dll files missing, right after installing Unity 0 Answers
Error stage @username 1 Answer
"error CS1525: Unexpected symbol `end-of-file' " I've tried everything.... 1 Answer