Initial commit
This commit is contained in:
68
Assets/Scripts/LightSwitch.cs
Normal file
68
Assets/Scripts/LightSwitch.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class LightSwitch : MonoBehaviour, IInteractable
|
||||
{
|
||||
[Header("Settings")]
|
||||
public Light linkedLight; // Drag the actual light source here
|
||||
public bool isLightOn = true;
|
||||
|
||||
[Header("Horror Mechanics")]
|
||||
[Range(0f, 1f)] public float malfunctionChance = 0.1f; // 10% chance to fail
|
||||
public AudioSource audioSource;
|
||||
public AudioClip switchClickSound;
|
||||
public AudioClip malfunctionSound;
|
||||
|
||||
void Start()
|
||||
{
|
||||
UpdateLightState();
|
||||
// Register this switch with the Game Manager
|
||||
if (GameManager.Instance != null) GameManager.Instance.RegisterSwitch(this);
|
||||
}
|
||||
|
||||
public void Interact()
|
||||
{
|
||||
// Random chance for the switch to get "stuck" or fail
|
||||
if (Random.value < malfunctionChance)
|
||||
{
|
||||
audioSource.PlayOneShot(malfunctionSound);
|
||||
return; // Exit without turning off light
|
||||
}
|
||||
|
||||
isLightOn = !isLightOn;
|
||||
audioSource.PlayOneShot(switchClickSound);
|
||||
UpdateLightState();
|
||||
|
||||
// Notify Manager to check if all lights are off
|
||||
GameManager.Instance.CheckLights();
|
||||
}
|
||||
|
||||
// Called by the Staircase Trigger to spook the player
|
||||
public void ForceLightOn()
|
||||
{
|
||||
isLightOn = true;
|
||||
audioSource.PlayOneShot(switchClickSound); // Hearing the click from downstairs is scary
|
||||
UpdateLightState();
|
||||
}
|
||||
|
||||
void UpdateLightState()
|
||||
{
|
||||
if (linkedLight != null) linkedLight.enabled = isLightOn;
|
||||
|
||||
// Optional: Change material of switch to look glowing/dark
|
||||
}
|
||||
|
||||
public string GetDescription()
|
||||
{
|
||||
{
|
||||
if (isLightOn)
|
||||
{
|
||||
return "Press [E] to turn light <color=red>OFF</color>";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Press [E] to turn light <color=green>ON</color>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user