Question by
LBardmask · Jan 10 at 03:57 AM ·
timerotate objectclocksun
sync directional lights rotation with in game custom clock
ok im trying to sync the scenes directional lights rotation to my in game clock with ui. its a standard 12 hr with am and pm. how do i rotate the sun so that it matches my clock heres my clock script. theres remnants from previous attempts to sync the rotation to the time. the time speed is 1 real minute is 30 minutes in game like oblivion.
public class Clock : MonoBehaviour
{
public float speed;
public int minutes;
public float hours;
public bool am;
public string daynight;
public int sunTime;
public int totalTime;
public Text time;
public bool tick;
public GameObject sun;
public void Start()
{
hours = 12;
minutes = 0;
am = false;
}
public void Update()
{
if (am)
daynight = " AM";
else
daynight = " PM";
if (!tick)
StartCoroutine(Ticker());
time.text = hours.ToString() + ":" + minutes.ToString("00") + daynight;
sun.transform.Rotate(Vector3.right * (.25f * Time.deltaTime));
}
public IEnumerator Ticker()
{
tick = true;
yield return new WaitForSeconds(speed);
minutes++;
if(minutes >= 60)
{
minutes = 0;
hours++;
if(hours >= 13)
{
hours = 1;
}
if(hours == 12)
am = !am;
}
if(am)
{
sunTime = (int)(((hours - 1) * 60) + minutes);
}
else
{
if(hours == 12)
{
sunTime = (int)(((hours * 2) * 60) + minutes);
}
else
{
sunTime = (int)((((hours + 12) * 2) * 60) + minutes);
}
}
totalTime++;
tick = false;
}
}
Comment