help!!!
实现功能:计时5秒后显示Iamge
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class time1 : MonoBehaviour {
int hour;
int minute;
int second;
int millisecond;
float timeSpend = 0.0f;
public GameObject cImage;
public Text text_timeSpend;
// Use this for initialization
void Start () {
cImage.active = false;
//canntImage.SetActive(false);
}
// Update is called once per frame
void Update () {
timeSpend += Time.deltaTime;
hour = (int)timeSpend / 3600;
minute = ((int)timeSpend - hour * 3600) / 60;
second = (int)timeSpend - hour * 3600 - minute * 60;
millisecond = (int)((timeSpend - (int)timeSpend) * 1000);
text_timeSpend.text = string.Format("{0:D2}:{1:D2}:{2:D2}.{3:D3}", hour, minute, second, millisecond);
if (second ==5)
{
cImage.active = true;
// canntImage.SetActive(true);
}
运行后显示:NullReferenceException: Object reference not set to an instance of an object求助解决