StellarXipher/Assets/Scripts/LightSwitchInteraction.cs

76 lines
2.2 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;
void Awake()
{
outline = GetComponent<Outline>();
if (outline != null)
{
outline.enabled = true;
}
if (interactionPrompt != null)
{
interactionPrompt.enabled = false;
}
}
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, 10f))
{
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;
}
}
}
else
{
if (interactionPrompt != null)
{
interactionPrompt.enabled = false;
}
}
}
else
{
if (interactionPrompt != null)
{
interactionPrompt.enabled = false;
}
}
}
}
}