每X分钟更新Unity AI文本



我有一年中的一天,一天中的一年零一个小时,在页面左上方形成UI文本值。我正在用日形阵列中的索引形成上面的索引,然后是一年的数字,然后是一个小时的索引。

例如,这创建以下内容:'1st janauary 2371 00:00'

我想在现实世界中每5分钟每5分钟将小时移动,然后到达23:00,重置小时数组,并增加1月2日的阵列,等等。

显示上述功能正常,但是当我尝试运行一个函数以每五分钟增加每小时的函数时,没有发生任何错误,但是控制台中没有错误。我尝试了一个联合行驶,我尝试使用一个函数进行调用,该函数会增加一个小时的当前数组索引,并且我还尝试了此功能,在此基础上再次设置了对UI文本的引用((;我也提到了UnityEngine.ui。

我的代码下面。谁能告诉我我要去哪里?就像我说的那样,当我启动游戏时,根据阵列索引的串联显示正确的日期,但是5秒钟后没有任何进展。

using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class PassageOfTime : MonoBehaviour
{
public float yearNo;
public string dayNo;
public int currentDay;
public string hourNo;
public int currentHour;
public string gameDateTime;

public Text DateTimeText;

string[] hourInDay = new string[]
{
"00:00",
"01:00",
"02:00",
"03:00",
"04:00",
"05:00",
"06:00",
"07:00",
"08:00",
"09:00",
"10:00",
"11:00",
"12:00",
"13:00",
"14:00",
"15:00",
"16:00",
"17:00",
"18:00",
"19:00",
"19:00",
"20:00",
"21:00",
"22:00",
"23:00"
};
string[] dayInYear = new string[]
{
  "January 1st",
  "January 2nd",
  "January 3rd",
  "January 4th",
  "January 5th",
  "January 6th",
  "January 7th",
  "January 8th",
  "January 9th",
  "January 10th",
  "January 11th",
  "January 12th",
  "January 13th",
  "January 14th",
  "January 15th",
  "January 16th",
  "January 17th",
  "January 18th",
  "January 19th",
  "January 20th",
  "January 21st",
  "January 22nd",
  "January 23rd",
  "January 24th",
  "January 25th",
  "January 26th",
  "January 27th",
  "January 28th",
  "January 29th",
  "January 30th",
  "January 31st",
  "February 1st",
  "Feburary 2nd"
};
void incrementYear()
{
    yearNo += 1;
}
void incrementDay()
{
    currentDay += 1;
    currentHour = 0;
}
void incrementHour()
{
    currentHour += 1;
}
void ProgressTime()
{
    incrementHour();
    DateTimeText = GetComponent<UnityEngine.UI.Text>();
    DateTimeText.text = gameDateTime;
}

// Use this for initialization
void Start()
{
    DateTimeText = GetComponent<UnityEngine.UI.Text>();
    currentDay = 0;
    currentHour = 0;
    dayNo = dayInYear[currentDay];
    hourNo = hourInDay[currentHour];
    yearNo = 2371;
    gameDateTime = dayNo + "  " + yearNo + "  " + hourNo;
    DateTimeText.text= gameDateTime.ToString();
    InvokeRepeating("ProgressTime", 5.0f, 5.0f);


}
// Update is called once per frame
void Update()
{
   DateTimeText.text = gameDateTime.ToString();
}

}

进行一些增量后,您需要设置GamedAtetime:

void ProgressTime()
{
    incrementHour();
    gameDateTime = dayNo + "  " + yearNo + "  " + hourNo;
    DateTimeText = GetComponent<UnityEngine.UI.Text>();
    DateTimeText.text = gameDateTime;

}

最新更新