diff --git a/Assets/Scripts/Interactables/LightSwitchView.cs b/Assets/Scripts/Interactables/LightSwitchView.cs index e96c6032..03630219 100644 --- a/Assets/Scripts/Interactables/LightSwitchView.cs +++ b/Assets/Scripts/Interactables/LightSwitchView.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using UnityEngine; using static LightSwitchView; @@ -6,16 +7,16 @@ public class LightSwitchView : MonoBehaviour, IInteractable { [SerializeField] private List lightsources = new List(); private SwitchState currentState; - public delegate void LightSwitchDelegate(); - public static LightSwitchDelegate lightToggled; + + public static event Action lightToggledAction; - private void OnEnable() => lightToggled += onLightSwitch; + private void OnEnable() => lightToggledAction += onLightSwitch; - private void OnDisable() => lightToggled -= onLightSwitch; + private void OnDisable() => lightToggledAction -= onLightSwitch; private void Start() => currentState = SwitchState.Off; - public void Interact() => lightToggled?.Invoke(); + public void Interact() => lightToggledAction?.Invoke(); private void toggleLights() { diff --git a/Assets/Scripts/Player/PlayerController.cs b/Assets/Scripts/Player/PlayerController.cs index 054fc215..2a14c50e 100644 --- a/Assets/Scripts/Player/PlayerController.cs +++ b/Assets/Scripts/Player/PlayerController.cs @@ -25,14 +25,15 @@ public PlayerController(PlayerView playerView, PlayerScriptableObject playerScri this.playerScriptableObject = playerScriptableObject; this.playerScriptableObject.KeysEquipped = 0; - LightSwitchView.lightToggled += onLightSwitch; + LightSwitchView.lightToggledAction += onLightSwitch; playerState = PlayerState.InDark; } ~PlayerController() { - LightSwitchView.lightToggled -= onLightSwitch; + LightSwitchView.lightToggledAction -= onLightSwitch; } + public void Interact() => IsInteracted = Input.GetKeyDown(KeyCode.E) ? true : (Input.GetKeyUp(KeyCode.E) ? false : IsInteracted); public void Jump(Rigidbody playerRigidbody, Transform transform)