166 lines
4.7 KiB
C#
166 lines
4.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System.Linq;
|
|
|
|
public class HallucinationsTrigger : MonoBehaviour
|
|
{
|
|
[Header("Light Flickering")]
|
|
public List<LightAnimationUpdate> lightAnimationUpdate;
|
|
[Header("Shadow Figures")]
|
|
public List<GameObject> shadowFiguresHallucinations; //Replace with a new script for shadow figures hallucinations because you might want to enable playable director with animations or something else.
|
|
[Header("Eyes")]
|
|
public List<HallucinationsEye> eyesHallucinations;
|
|
|
|
[SerializeField] int randomMinorHallucinationIndex;
|
|
[SerializeField] private int maxMinorHallucinations;
|
|
|
|
bool isOnTrigger;
|
|
|
|
private void Start()
|
|
{
|
|
if (Sanity.GetInstance() != null)
|
|
{
|
|
Sanity.GetInstance().OnSane += DisableAllHallucinations;
|
|
print("Subscribe (DisableAllHallucinations) ON START");
|
|
}
|
|
StartCoroutine(LateStart());
|
|
}
|
|
|
|
IEnumerator LateStart()
|
|
{
|
|
yield return new WaitForSeconds(0.5f);
|
|
if (Sanity.GetInstance() != null)
|
|
{
|
|
Sanity.GetInstance().OnSane += DisableAllHallucinations;
|
|
print("Subscribe (DisableAllHallucinations) ON LATE START");
|
|
}
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
if (Sanity.GetInstance() != null)
|
|
{
|
|
Sanity.GetInstance().OnSane += DisableAllHallucinations;
|
|
print("Subscribe (DisableAllHallucinations)");
|
|
}
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
if (Sanity.GetInstance() != null)
|
|
{
|
|
Sanity.GetInstance().OnSane -= DisableAllHallucinations;
|
|
print("Unsubscribe (DisableAllHallucinations)");
|
|
}
|
|
}
|
|
|
|
private void OnTriggerStay(Collider other)
|
|
{
|
|
if (other.gameObject.CompareTag("Player") && !isOnTrigger)
|
|
{
|
|
if (Sanity.GetInstance().mentalState == Sanity.SanityState.MinorHallucinations)
|
|
{
|
|
randomMinorHallucinationIndex = Random.Range(0, maxMinorHallucinations);
|
|
|
|
switch (randomMinorHallucinationIndex)
|
|
{
|
|
case 0:
|
|
StartFlickeringLightsHallucinations();
|
|
break;
|
|
case 1:
|
|
StartShadowFiguresHallucinations();
|
|
break;
|
|
case 2:
|
|
StartEyeHallucinations();
|
|
break;
|
|
}
|
|
isOnTrigger = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
if (other.gameObject.CompareTag("Player") && isOnTrigger)
|
|
{
|
|
isOnTrigger = false;
|
|
}
|
|
}
|
|
|
|
public void StartFlickeringLightsHallucinations()
|
|
{
|
|
if (lightAnimationUpdate.Any())
|
|
{
|
|
foreach (var _lightAnimationUpdate in lightAnimationUpdate)
|
|
{
|
|
_lightAnimationUpdate.StartFlickering();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void StopFlickeringLightsHallucinations()
|
|
{
|
|
if (lightAnimationUpdate.Any())
|
|
{
|
|
foreach (var _lightAnimationUpdate in lightAnimationUpdate)
|
|
{
|
|
_lightAnimationUpdate.StopFlickering();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void StartShadowFiguresHallucinations()
|
|
{
|
|
if (shadowFiguresHallucinations.Any())
|
|
{
|
|
foreach (var _shadowFiguresHallucinations in shadowFiguresHallucinations)
|
|
{
|
|
_shadowFiguresHallucinations.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void StopShadowFiguresHallucinations()
|
|
{
|
|
if (shadowFiguresHallucinations.Any())
|
|
{
|
|
foreach (var _shadowFiguresHallucinations in shadowFiguresHallucinations)
|
|
{
|
|
_shadowFiguresHallucinations.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void StartEyeHallucinations()
|
|
{
|
|
if (eyesHallucinations.Any())
|
|
{
|
|
foreach (var _eyesHallucinations in eyesHallucinations)
|
|
{
|
|
_eyesHallucinations.gameObject.SetActive(true);
|
|
_eyesHallucinations.EyeIsWatching();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void StopEyeHallucinations()
|
|
{
|
|
if (eyesHallucinations.Any())
|
|
{
|
|
foreach (var _eyesHallucinations in eyesHallucinations)
|
|
{
|
|
_eyesHallucinations.EyeIsNoLongerWatching();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void DisableAllHallucinations()
|
|
{
|
|
print("Disable hallucinations: "+ gameObject.name);
|
|
StopFlickeringLightsHallucinations();
|
|
//StopShadowFiguresHallucinations();
|
|
StopEyeHallucinations();
|
|
}
|
|
}
|