What is the best way to search a text clock UI for certain times
Hi all, Just wondering if anyone could help me out with the below. I'm trying to use the text based clock I have set up to trigger events based on the in game time. However the function " if (timeText.text =="00:00")" doesn't seem to work and never gets triggered, is there a better way to do this? I have tried a couple of different ways, but I haven't had any luck yet.
[CODE=CSharp]
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class Lights : MonoBehaviour {
public Animator animator;
public Text timeText;
private string lightsontrigger = "22:00";
private string lightson = "20:00";
private string lightsofftrigger = "05:30";
private string lightsoff = "09:00";
void Start ()
{
timeText = GameObject.Find("timeText").GetComponent<Text>();
animator.SetBool("isDawn", false);
animator.SetBool("isDay", false);
animator.SetBool("isDusk", false);
animator.SetBool("isNight", false);
if (timeText.text == lightsontrigger)
{
animator.SetBool("isDawn", true);
animator.SetBool("isDay", false);
animator.SetBool("isDusk", false);
animator.SetBool("isNight", false);
Debug.Log("it is dawn");
}
if (timeText.text == "09:00")
{
animator.SetBool("isDawn", false);
animator.SetBool("isDay", true);
animator.SetBool("isDusk", false);
animator.SetBool("isNight", false);
Debug.Log("it is day");
}
if (timeText.text =="20:00")
{
animator.SetBool("isDawn", false);
animator.SetBool("isDay", false);
animator.SetBool("isDusk", true);
animator.SetBool("isNight", false);
Debug.Log("it is dusk");
}
if (timeText.text == "22:00")
{
animator.SetBool("isDawn", false);
animator.SetBool("isDay", false);
animator.SetBool("isDusk", false);
animator.SetBool("isNight", true);
Debug.Log("it is Night");
}
}
} [/CODE]
Are you sure it reaches “00:00” and not “24:00” and then “00:01”?
Your answer
Follow this Question
Related Questions
Can you have event listeners that are in the parent and child? 0 Answers
[Beginner] [UI text] Adapt the size of the text zone to the text inside 2 Answers
How can I do a timer with this script? 1 Answer
How to export in a text file float numbers generated in a list 1 Answer
How to call function on AssetDatabase.importPackageCompleted 1 Answer