StellarXipher/Assets/Scripts/LightSwitchInteraction.cs
EthanPisani f319ba2bf1
All checks were successful
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Successful in 5m53s
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Successful in 5m30s
Build project / Publish to itch.io (StandaloneLinux64) (push) Successful in 4s
Build project / Publish to itch.io (StandaloneWindows64) (push) Successful in 4s
reworked tablet and mines, polished level1 to MVP
2025-03-18 02:36:07 -04:00

116 lines
3.7 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class LightSwitchInteraction : MonoBehaviour
{
public CeilingLightController[] ceilingLights;
public TMP_Text interactionPrompt;
private bool isLightsFixed = false;
private Outline outline;
[SerializeField] private Animator leverAnimator;
[SerializeField] private AudioClip leverSound;
[SerializeField] private string animationFile = "DoorAnimation.013";
[SerializeField] private Animator myDoor = null;
[SerializeField] private GameObject enableAfterLightsFixed = null;
void Awake()
{
outline = GetComponent<Outline>();
if (outline != null)
{
outline.enabled = true;
}
if (interactionPrompt != null)
{
interactionPrompt.enabled = false;
}
}
void PlayDoorAnimation()
{
if (myDoor != null)
{
myDoor.Play(animationFile);
}
}
void Update()
{
if (!isLightsFixed)
{
Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
if (Physics.Raycast(ray, out RaycastHit hit, 5f))
{
if (hit.collider.gameObject == gameObject)
{
if (interactionPrompt != null)
{
interactionPrompt.text = "Left click to turn emergency power on";
interactionPrompt.enabled = true;
}
if (Input.GetMouseButtonDown(0))
{
foreach (CeilingLightController light in ceilingLights)
{
light.StopFading();
}
LightSwitchManager.IsLightSwitchActivated = true;
isLightsFixed = true;
if (outline != null)
{
outline.enabled = false;
}
if (interactionPrompt != null)
{
interactionPrompt.enabled = false;
}
// Play Animation for lever
if (leverAnimator != null)
{
leverAnimator.Play("EmergeLeverPull",0,0.0f);
}
// Play Sound for lever
if (leverSound != null)
{
Debug.Log("Playing sound: " + leverSound.name);
SoundFXManager.instance.PlaySound(leverSound, transform, 2.0f);
}
// open door after audio is done
if (enableAfterLightsFixed != null)
{
Debug.Log("Enabling audio clip");
// enable box collider of object
enableAfterLightsFixed.GetComponent<BoxCollider>().enabled = true;
}
if (myDoor != null)
{
Invoke("PlayDoorAnimation", 16.0f);
}
}
}
else
{
if (interactionPrompt != null)
{
interactionPrompt.enabled = false;
}
}
}
else
{
if (interactionPrompt != null)
{
interactionPrompt.enabled = false;
}
}
}
}
}