Member-only story
Unity: Creating a day-night cycle
In some games, it is useful to have a day and night cycle. For example, In Mystery Queen, the creatures of the world behave differently depending on the time of day, e.g., Slimey is only active when the sun is up, and goes to sleep at dusk.
In this guide, I’ll discuss how to create a day-night cycle with the lighting system in Unity 2D, so that you can incorporate similar systems in your game! Similar to my previous guide on creating a translucent effect, I will be walking through the steps here, and also providing downloadable Unity packages (Step 0, Steps 1–5) and a Github page. Since we’ll be changing project settings, Step 0 (the initial setup) and later steps will be in separate projects. The projects and code have been created to be easier to understand over efficiency, so you may want to do some optimizations and customizations for your own project.
The screenshots below are from Unity 2019.4, so if you’re using a different version, the menus may not be exactly the same.
Step 0: Setting up the scene in Unity
We’re going to set up a scene in Unity with a single NPC: a wolf. Similar to our last guide, we’re using freely-available sprites from the Liberated Pixel Cup (LPC). In this case, we’re using sprites from the [LPC] Wolf Animation. For the purposes of this guide, we won’t be…