- Home /
Question by
CrunchySushi · Jan 09, 2018 at 08:59 AM ·
timeclock
Start my Clock script at 6am?
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ClockScript : MonoBehaviour
{
Text clocktxt;
public GameObject amWord; // just am word for dispaly
public GameObject pmWord; // just pm word for display
public GameObject amWordWhite; // just am word for dispaly
public GameObject pmWordWhite; // just pm word for display
private float RawTime = 0.0F;
private float ClockHR = 0.0F;
private float ClockMN = 0.0F;
private int ClockSpeedMultiplier = 2;
void Start()
{
clocktxt = gameObject.GetComponent<Text>();
}
void Update()
{
RawTime += Time.deltaTime * ClockSpeedMultiplier;
ClockHR = (int)RawTime / 60;
ClockMN = (int)RawTime - (int)ClockHR * 60;
if (RawTime >= 1440)
{
RawTime = 0;
}
if (RawTime >= 720)
{
amWord.SetActive(false);
pmWord.SetActive(true);
amWordWhite.SetActive(true);
pmWordWhite.SetActive(false);
ClockHR -= 12;
}
else
{
amWord.SetActive(true);
pmWord.SetActive(false);
amWordWhite.SetActive(false);
pmWordWhite.SetActive(true);
}
if (ClockHR < 1)
{
ClockHR = 12;
}
clocktxt.text = ClockHR.ToString("0 0 ") + ":" + ClockMN.ToString(" 0 0");
}
}
Any help would be appreciated!! It currently starts at 12am...
Comment
Answer by dev-waqas · Jan 09, 2018 at 11:18 AM
Simply set the initial value of Variable Raw Time. Something like this.
void Start()
{
RawTime = 360.0f;
clocktxt = gameObject.GetComponent<Text>();
}
Your answer
Follow this Question
Related Questions
Clock Trigger 2 Answers
Javascript beginner here: how do I implement time such as hours and days? 2 Answers
In game clock/Time 1 Answer
animation control by time/clock 2 Answers
Why in game time is correct in dev env. but not in browser 1 Answer