All checks were successful
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Successful in 1h9m47s
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Successful in 22m28s
Build project / Publish to itch.io (StandaloneLinux64) (push) Successful in 16s
Build project / Publish to itch.io (StandaloneWindows64) (push) Successful in 14s
77 lines
2.2 KiB
C#
77 lines
2.2 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class CeilingLightController : MonoBehaviour
|
|
{
|
|
private Light ceilingLight;
|
|
private Coroutine fadeCoroutine;
|
|
private bool isFading = true;
|
|
private Color defaultColor;
|
|
private float defaultIntensity;
|
|
public float fadeDuration = 0.5f;
|
|
[SerializeField] public AudioClip soundClip;
|
|
private AudioSource loopingSound;
|
|
|
|
void Start()
|
|
{
|
|
ceilingLight = GetComponent<Light>();
|
|
defaultColor = ceilingLight.color;
|
|
defaultIntensity = ceilingLight.intensity;
|
|
ceilingLight.color = Color.red;
|
|
ceilingLight.intensity = 0;
|
|
fadeCoroutine = StartCoroutine(FadeInOut());
|
|
|
|
// Start looping sound
|
|
if (SoundFXManager.instance != null && soundClip != null)
|
|
{
|
|
loopingSound = SoundFXManager.instance.PlayLoopingSound(soundClip, transform, 0.01f);
|
|
}
|
|
}
|
|
|
|
IEnumerator FadeInOut()
|
|
{
|
|
while (isFading)
|
|
{
|
|
float timer = 0f;
|
|
while (timer < fadeDuration)
|
|
{
|
|
timer += Time.deltaTime;
|
|
float t = timer / fadeDuration;
|
|
ceilingLight.intensity = Mathf.Lerp(0, defaultIntensity, t);
|
|
yield return null;
|
|
}
|
|
|
|
ceilingLight.intensity = defaultIntensity;
|
|
timer = 0f;
|
|
|
|
while (timer < fadeDuration)
|
|
{
|
|
timer += Time.deltaTime;
|
|
float t = timer / fadeDuration;
|
|
ceilingLight.intensity = Mathf.Lerp(defaultIntensity, 0, t);
|
|
yield return null;
|
|
}
|
|
ceilingLight.intensity = 0;
|
|
}
|
|
}
|
|
|
|
public void StopFading()
|
|
{
|
|
if (fadeCoroutine != null)
|
|
{
|
|
StopCoroutine(fadeCoroutine);
|
|
fadeCoroutine = null;
|
|
}
|
|
isFading = false;
|
|
ceilingLight.color = defaultColor;
|
|
ceilingLight.intensity = defaultIntensity;
|
|
|
|
// Stop looping sound
|
|
if (SoundFXManager.instance != null && loopingSound != null)
|
|
{
|
|
SoundFXManager.instance.StopLoopingSound(loopingSound);
|
|
loopingSound = null;
|
|
}
|
|
}
|
|
}
|