Example #1
0
 // Start is called before the first frame update
 void Start()
 {
     //thisObject = this.gameObject;
     //objectMaterial = GetComponent<Material>();
     sun      = GameObject.FindGameObjectWithTag("sun");
     dayCycle = sun.GetComponent <DayCycles>(); //get the script from the sun
 }
Example #2
0
    void Update()
    {
        // Update cycle time
        cycleCurrentTime += Time.deltaTime;

        // Check if cycle time reach cycle duration time
        if (((dayCycle == DayCycles.Sunrise || dayCycle == DayCycles.Sunset) && cycleCurrentTime >= cycleMaxTime / 2) ||
            (cycleCurrentTime >= cycleMaxTime && (dayCycle != DayCycles.Sunrise || dayCycle != DayCycles.Sunset)))
        {
            cycleCurrentTime = 0; // back to 0 (restarting cycle time)
            dayCycle++;           // change cycle state
        }

        // If reach final state we back to sunrise (Enum id 0)
        if (dayCycle > DayCycles.Midnight)
        {
            dayCycle = 0;
        }

        // percent it's a value between current and max time to make a color lerp smooth
        float percent = cycleCurrentTime / cycleMaxTime;

        // Sunrise state (you can do a lot of stuff based on every cycle state, like enable animals only in sunrise )
        if (dayCycle == DayCycles.Sunrise)
        {
            ControlLightMaps(false); // disable map light (keep enable only at night)
            globalLight.color     = Color.Lerp(sunrise, day, percent);
            globalLight.intensity = Mathf.Lerp(sunriseIntensity, dayIntensity, percent);
        }

        // Mid Day state
        if (dayCycle == DayCycles.Day)
        {
            globalLight.color     = Color.Lerp(day, sunset, percent);
            globalLight.intensity = Mathf.Lerp(dayIntensity, sunriseIntensity, percent);
        }

        // Sunset state
        if (dayCycle == DayCycles.Sunset)
        {
            globalLight.color     = Color.Lerp(sunset, night, percent);
            globalLight.intensity = Mathf.Lerp(sunriseIntensity, nightIntensity, percent);
        }

        // Night state
        if (dayCycle == DayCycles.Night)
        {
            ControlLightMaps(true); // enable map lights (disable only in day states)
            globalLight.color     = Color.Lerp(night, midnight, percent);
            globalLight.intensity = Mathf.Lerp(nightIntensity, midnightIntensity, percent);
        }

        // Midnight state
        if (dayCycle == DayCycles.Midnight)
        {
            globalLight.color     = Color.Lerp(midnight, sunrise, percent);
            globalLight.intensity = Mathf.Lerp(midnightIntensity, sunriseIntensity, percent);
        }
    }
Example #3
0
    public Light2D[] mapLights; // enable/disable in day/night states

    void Start()
    {
        dayCycle          = DayCycles.Sunrise; // start with sunrise state
        globalLight.color = sunrise;           // start global color at sunrise

        // Static variables to keep time after switching scenes
        cycleCurrentTime = globalCurrentTime;
        dayCycle         = globalCurrentDayCycle;

        staticMaxTime = cycleMaxTime;
    }
    public Light2D[] mapLights; // enable/disable in day/night states

    void Start()
    {
        int scene = SceneManager.GetActiveScene().buildIndex;

        if (scene == 3)
        {
            dayCycle          = DayCycles.Night; // start with sunrise state
            globalLight.color = night;           // start global color at sunrise
        }

        else if (scene == 2)
        {
            dayCycle          = DayCycles.Day; // start with sunrise state
            globalLight.color = day;           // start global color at sunrise
        }
    }
Example #5
0
    public Light2D[] mapLights; // enable/disable in day/night states

    void Start()
    {
        dayCycle          = DayCycles.Sunrise; // start with sunrise state
        globalLight.color = sunrise;           // start global color at sunrise
    }