Making a RTS game #11: Adding a day-and-night cycle (Unity/C#)

Making a RTS game #11: Adding a day-and-night cycle (Unity/C#)

On with our RTS game: today, we add a day-and-night cycle!

In the last tutorial, we talked about camera placement and projections. We saw how crucial the position and properties of the camera in order to convey the proper look and feel for your game. Another essential component of this ambiance is the lighting of your scene.

Time is of the utmost importance in almost all video games, be it because it is part of the story itself (like in Majora’s Mask), because you’re required to time your actions very precisely (like in the infamous Dragon’s Lair — considered the first QTE game), because you have limited time to complete a mission (like for some World of Warcraft quests), because you need to wait for something to happen (like in Minecraft, when you want your crops to grow)…

Time might be a simple continuous countdown, or it might match some sort of day and night cycle, as we have in real life.

For example, in MMORPGs where players need to rejoin and play together (and thus share the same “world clock”), the time in-game matches the time in real life and the day-/night-time (based on the server timezone). At the other end of the spectrum, a small game like Tools Up! (2019) relies heavily on time constraints (you have a given amount of minutes to complete the level) but it has absolutely no use for an actual day/night cycle. And so in-between, you have games that have a somewhat realistic day/night cycle mechanism. The Final Fantasy series, Don’t Starve, Starcraft, Sea of Thieves, Minecraft (or the way more recent Valheim)… all have gameplays that incorporate day- and night-time. Depending on the game, the effect of time varies but it almost always has an impact on the rest of the game systems.

In strategy games, it is often used both for storylines and to slightly alter the gameplay so the players stay on their toes.

Our day and night cycle will rely on a set of lights that rotate continuously so that a different light in the set is directed towards the ground depending on the period of the (in-game) day. For now, this cycle won’t have any direct impact on the game other than the lighting of the scene. However in the final game, it might be similar to Warcraft 3’s day/night cycle and:

  • change unit’s health regeneration (both yours and the enemy’s/NPCs’)
  • alter unit’s sight of vision
  • modify the creepers that pop around
  • allow/prevent certain skills from being triggered

Thanks to our event system, it will be fairly easy to hook up the “sun is up” or “sun is down” moments to events emitting and thus catch this specific scene property in our other game systems.

unity csharp games tutorial

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Making a RTS game #10: Moving the camera (Unity/C#)

In this article, I will guide you to Make RTS Game #10: Switch Camera (Unity/C#)

Build a 2D Platformer Game in Unity | Unity Beginner Tutorial

In this beginner tutorial, you will learn how to build a 2D game in Unity from scratch. You don't need any programming experience to follow along. In this part, we will install the Unity Hub, Unity, and Visual Studio.

Unity Game Development Company | Hire Unity Developers

Trusted Unity game development company offering Unity 3D and 2D development, Video game development, etc. Hire Unity developers to build Unity softwares.

Unity Game Development Company | Hire Unity Developers

Trusted Unity game development company offering Unity 3D and 2D development, Video game development, etc. Hire Unity developers to build Unity softwares.

Game Development with .NET

.NET is cross-platform. With .NET you can target over 25+ different platforms with a single code base. You can make games for, but not limited to, Windows, macOS, Linux, Android, iOS, Xbox, PlayStation, Nintendo, and mixed reality devices.