So I followed a how-to video on how to implement a day and night cycle. However, once I enter “play” mode, nothing happens. There aren’t any compilation errors and I set-up the universal pipeline renderer asset as instructed by the video. Attached is a screen shot of how I have the game object “Global Light 2D” set-up and also the C# script.
Day-and-night
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.Rendering.Universal;
public class DayAndNightCycle : MonoBehaviour
{
[SerializeField] private Gradient lightColor;
[SerializeField] private Light2D light;
private int days;
public int Days => days;
private float time = 50;
private bool canChangeDay = true;
private void Update()
{
if(time > 500)
{
time = 0;
}
if((int)time == 250 && canChangeDay)
{
canChangeDay = false;
days++;
}
if ((int)time == 255)
canChangeDay = true;
time += Time.deltaTime;
light.GetComponent<Light2D>().color = lightColor.Evaluate(time * 0.002f);
}
}
Script
