Search code examples
androidunity-game-enginecycle

Day/night cycle in Unity3D depending of the hour of the device


Hello: I have seen lots of tutorials about day-night cycle in Unity,but I want something more concrete. I have searched a lot on the Internet but I didn't find nothing about this. I want to synchronize the sun cycle with the clock of my android device(i.e: smartphone).When it's 7 am in the clock,the sun will start to rise,and when it's 10 pm in the clock, the sun will start to go down. I can't find any script. Please,can you help me? Thanks. Frank


Solution

  • Read this: Source

    int sysHour = System.DateTime.Now.Hour;
    if(sysHour > 13)
    Debug.Log("Afternoon");
    else if(sysHour > 8)
    Debug.Log("Morning");
    else
    Debug.Log("Night");