LightLurch ability
Makes the lurch glow. Can increase and decrease light as well as emission if the special "LightUp" ability is used.
This commit is contained in:
131
Assets/Scripts/LightLurch.cs
Normal file
131
Assets/Scripts/LightLurch.cs
Normal file
@@ -0,0 +1,131 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LightLurch : MonoBehaviour {
|
||||
|
||||
private enum states { standard, lit, unlit }
|
||||
[Header("Distances")]
|
||||
[SerializeField]
|
||||
private float standardRadius, standardIntensity;
|
||||
[SerializeField]
|
||||
private float tinyRadius, tinyIntensity;
|
||||
[SerializeField]
|
||||
private float maxRadius, maxIntensity;
|
||||
[Header("Emission")]
|
||||
[SerializeField]
|
||||
private float emissionMultiplier = 1;
|
||||
private float emissionValue;
|
||||
[SerializeField]
|
||||
private float maxEmission, minEmission, baseEmission = 1;
|
||||
|
||||
private float intensitySnapshot;
|
||||
private Light lightSource;
|
||||
private Renderer lurchRenderer;
|
||||
|
||||
[SerializeField]
|
||||
private KeyCode triggerButton;
|
||||
[SerializeField]
|
||||
private float litDuration;
|
||||
[SerializeField]
|
||||
private float unLitDuration;
|
||||
[SerializeField]
|
||||
private float animationSpeed;
|
||||
|
||||
[Header("Debug")]
|
||||
[SerializeField]
|
||||
private states state;
|
||||
[SerializeField]
|
||||
private float t = 0;
|
||||
[SerializeField]
|
||||
private float ldCounter;
|
||||
private float llCounter;
|
||||
|
||||
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
state = states.standard;
|
||||
GameObject lurch = GetComponent<LurchMovement>().theLurch.gameObject;
|
||||
lightSource = lurch.GetComponent<Light>();
|
||||
lurchRenderer = lurch.GetComponent<Renderer>();
|
||||
lightSource.color = lurchRenderer.material.GetColor("_Color");
|
||||
intensitySnapshot = lightSource.intensity;
|
||||
lurchRenderer.material.SetColor("_EmissionColor", lightSource.color * (emissionMultiplier * emissionValue));
|
||||
emissionValue = baseEmission;
|
||||
lurchRenderer.material.EnableKeyword("_EMISSION");
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
t += Time.deltaTime * animationSpeed;
|
||||
lurchRenderer.material.SetColor("_EmissionColor", lightSource.color * (emissionMultiplier * emissionValue));
|
||||
switch (state)
|
||||
{
|
||||
case states.standard:
|
||||
StandardGlow();
|
||||
break;
|
||||
case states.lit:
|
||||
LightUp();
|
||||
break;
|
||||
case states.unlit:
|
||||
GlowLow();
|
||||
break;
|
||||
}
|
||||
if (Input.GetKeyDown(triggerButton) && state == states.standard)
|
||||
{
|
||||
t = 0;
|
||||
ldCounter = litDuration;
|
||||
llCounter = animationSpeed;
|
||||
state = states.lit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void StandardGlow()
|
||||
{
|
||||
lightSource.intensity = Mathf.Lerp(tinyIntensity, standardIntensity, t);
|
||||
lightSource.range = Mathf.Lerp(tinyRadius, standardRadius, t);
|
||||
emissionValue = Mathf.Lerp(minEmission, baseEmission, t);
|
||||
|
||||
}
|
||||
|
||||
private void LightUp()
|
||||
{
|
||||
lightSource.intensity = Mathf.Lerp(standardIntensity, maxIntensity, t);
|
||||
lightSource.range = Mathf.Lerp(standardRadius, maxRadius, t);
|
||||
emissionValue = Mathf.Lerp(baseEmission, maxEmission, t);
|
||||
|
||||
if (ldCounter <= 0)
|
||||
{
|
||||
t = 0;
|
||||
state = states.unlit;
|
||||
ldCounter = unLitDuration;
|
||||
llCounter = animationSpeed;
|
||||
return;
|
||||
}
|
||||
ldCounter -= Time.deltaTime;
|
||||
|
||||
}
|
||||
|
||||
private void GlowLow()
|
||||
{
|
||||
lightSource.intensity = Mathf.Lerp(maxIntensity, tinyIntensity, t);
|
||||
lightSource.range = Mathf.Lerp(maxRadius, tinyRadius, t);
|
||||
emissionValue = Mathf.Lerp(maxEmission, minEmission, t);
|
||||
|
||||
|
||||
if (llCounter <= 0)
|
||||
{
|
||||
if (ldCounter <= 0)
|
||||
{
|
||||
t = 0;
|
||||
state = states.standard;
|
||||
llCounter = animationSpeed;
|
||||
return;
|
||||
}
|
||||
ldCounter -= Time.deltaTime;
|
||||
}
|
||||
llCounter -= Time.deltaTime;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/LightLurch.cs.meta
Normal file
11
Assets/Scripts/LightLurch.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b614d5a678d653549b924deec5548458
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/TriggerEffects.meta
Normal file
8
Assets/Scripts/TriggerEffects.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8b7c82b907af1c45a4d5abd120ab492
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
63
Assets/Scripts/TriggerEffects/DarkAmbience.cs
Normal file
63
Assets/Scripts/TriggerEffects/DarkAmbience.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/TriggerEffects/DarkAmbience.cs.meta
Normal file
11
Assets/Scripts/TriggerEffects/DarkAmbience.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f0436f919a77164da3e5047c1b7795f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user