I made this day-night system that rotates the sun slowly but i want it set up that the game starts at 6am.
using UnityEngine;
using System.Collections;
public class DayNightSystem : MonoBehaviour {
public string time;
public float timeSpeed = 1.0f;
private float currentTime;
private float maxTime = 86400.0f;
// Use this for initialization
void Start () {
time = System.DateTime.Now.ToString("hh:mm:ss");
SetToRealTime ();
float rot = 360 * (currentTime/maxTime)-90;
transform.rotation = Quaternion.Euler (0, 0, rot);
}
// Update is called once per frame
void Update () {
float rot = (360 * (1 / maxTime))*Time.deltaTime*timeSpeed;
transform.Rotate (0, 0, rot);
if(currentTime > maxTime){
currentTime -= maxTime;
}
currentTime += Time.deltaTime * timeSpeed;
SetTimeString ();
}
void SetToRealTime(){
currentTime = 0.0f;
currentTime += System.DateTime.Now.Hour * 3600;
currentTime += System.DateTime.Now.Minute * 60;
currentTime += System.DateTime.Now.Second;
}
void SetTimeString(){
float sec2 = currentTime;
time = "";
int hours = Mathf.FloorToInt (sec2 / 3600);
sec2 -= hours * 3600;
int minutes = Mathf.FloorToInt (sec2 / 60);
sec2 -= minutes * 60;
int seconds = Mathf.FloorToInt (sec2);
sec2 -= hours;
time += hours.ToString () + ":" + minutes.ToString() + ":" + seconds.ToString();
}
}