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(); 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().enabled = true; } if (myDoor != null) { Invoke("PlayDoorAnimation", 1.0f); } } } else { if (interactionPrompt != null) { interactionPrompt.enabled = false; } } } else { if (interactionPrompt != null) { interactionPrompt.enabled = false; } } } } }