2
\$\begingroup\$

How do I make it so the texture of my plane is a black sky when it's night according to player's local time (say from 10 PM to 5 AM it's going to be black, and from 6 AM to 9 AM it's going to be a blue sky)?

Blue sky texture name is "bluesky" Black sky texture name is "blacksky"

Thanks.

\$\endgroup\$
  • 1
    \$\begingroup\$ I'll get you halfway there: System.DateTime.Now.Hour \$\endgroup\$ – Robert Rouhani Jul 3 '13 at 8:53
  • 5
    \$\begingroup\$ I'd definitely think twice about doing something like that to the player: You're essentially forcing people to experience the game based on their local time. So if they're only able to play at night, they'll never see the daylight in your game. In a similar fashion, they might feel forced to modify their local PC clock just to experience everything. Either way, I'd consider this bad design rather than immersive gameplay or anything similar. Only do it, if you've got a very, very good reason to do it. \$\endgroup\$ – Mario Jul 3 '13 at 9:52
  • 1
    \$\begingroup\$ I agree with Mario (I played a game like this once, always at night, and I eventually got stuck because I didn't play during daytime). If you do this, compress time so that a couple of minutes of real time increment game time by an hour. (See Terraria for a reference) \$\endgroup\$ – ashes999 Jul 3 '13 at 10:38
  • 2
    \$\begingroup\$ Let's not be judging his design - he's asking a technical question. not what you think of his game. A lot of great games were probably "DUMB" in the eyes of those that didn't get the goal or destination. \$\endgroup\$ – Tim Holt Aug 7 '13 at 5:29
  • 1
    \$\begingroup\$ Seems like this is two questions: (a) how do I tell the player's local time and (b) how do I interpolate between textures. \$\endgroup\$ – Trevor Powell Aug 7 '13 at 8:06
2
\$\begingroup\$

See How do I blend 2 lightmaps for day/night cycle in Unity? for a previous question about fading 2 lightmaps for day/night cycles. It includes an answer that seems to indicate how to do it. Your challenge will be to get the current time, figure out how much day/night sky you want given that time, and make it so.

In the answer given to the linked question, the shader has a "_Blend" value that you can set between 0.0 and 1.0. 0.0 is fully one skybox, and 1.0 is fully the other. What you'll want to do is have it be one value during the day, and the other during the night. Then as the sun goes down, change to the other. As it rises the next day, change back.

\$\endgroup\$
0
\$\begingroup\$

Check if System.DateTime.Now.Hour is between the hours you consider to be the night (it is 24h based) and change the skybox texture accordingly and dim all natural lights as well.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.