Files
lurchvolution/Assets/Scripts/TriggerEffects/DarkAmbience.cs
Jan Groß 9da1f82f20 LightLurch ability
Makes the lurch glow.
Can increase and decrease light as well as emission if the special "LightUp" ability is used.
2018-09-01 17:30:37 +02:00

64 lines
1.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DarkAmbience : MonoBehaviour {
private float defaultEnvLightingIntensity, defaultEnfReflectionIntensity;
[SerializeField]
private float targetEnvLightingIntensity, targetEnfReflectionIntensity;
[SerializeField]
private float lerpSpeed;
[SerializeField]
private bool isDark = false;
private float t = 0;
// Use this for initialization
void Start () {
defaultEnvLightingIntensity = RenderSettings.ambientIntensity;
defaultEnfReflectionIntensity = RenderSettings.reflectionIntensity;
}
public void SwitchDarkness(bool dark)
{
isDark = dark;
t = 0;
}
private void OnValidate()
{
t = 0;
}
private void OnTriggerEnter(Collider other)
{
if(other.transform.root.tag == "Player")
{
SwitchDarkness(true);
}
}
private void OnTriggerExit(Collider other)
{
if (other.transform.root.tag == "Player")
{
SwitchDarkness(false);
}
}
// Update is called once per frame
void Update () {
if(isDark)
{
RenderSettings.ambientIntensity = Mathf.Lerp(defaultEnvLightingIntensity, targetEnvLightingIntensity, t);
RenderSettings.reflectionIntensity = Mathf.Lerp(defaultEnfReflectionIntensity, targetEnfReflectionIntensity, t);
}
else
{
RenderSettings.ambientIntensity = Mathf.Lerp(targetEnvLightingIntensity, defaultEnvLightingIntensity, t);
RenderSettings.reflectionIntensity = Mathf.Lerp(targetEnfReflectionIntensity, defaultEnfReflectionIntensity , t);
}
t += Time.deltaTime * lerpSpeed;
}
}