diff --git a/Assets/Scenes/MainMenu.unity b/Assets/Scenes/MainMenu.unity index c8a04e61..28069ae2 100644 --- a/Assets/Scenes/MainMenu.unity +++ b/Assets/Scenes/MainMenu.unity @@ -123,7 +123,11 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +<<<<<<< HEAD +--- !u!1001 &466576513 +======= --- !u!1001 &457845157 +>>>>>>> 160156fb4b631d530b8e2b29fa5e180dc6f4714d PrefabInstance: m_ObjectHideFlags: 0 serializedVersion: 2 diff --git a/Assets/Scripts/Camera/CameraView.cs b/Assets/Scripts/Camera/CameraView.cs index 1e140553..60d65302 100644 --- a/Assets/Scripts/Camera/CameraView.cs +++ b/Assets/Scripts/Camera/CameraView.cs @@ -14,13 +14,19 @@ public class CameraView : MonoBehaviour private void OnEnable() { EventService.Instance.OnLightsOffByGhostEvent.AddListener(Shake); - EventService.Instance.PlayerDeathEvent.AddListener(Shake); + EventService.Instance.OnPlayerDeathEvent.AddListener(Shake); + EventService.Instance.OnRatRush.AddListener(Shake); + EventService.Instance.OnSkullDrop.AddListener(Shake); + } private void OnDisable() { EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(Shake); - EventService.Instance.PlayerDeathEvent.RemoveListener(Shake); + EventService.Instance.OnPlayerDeathEvent.RemoveListener(Shake); + EventService.Instance.OnRatRush.RemoveListener(Shake); + EventService.Instance.OnSkullDrop.RemoveListener(Shake); + } private void Start() @@ -76,4 +82,4 @@ private void stopCoroutine(Coroutine coroutine) StopCoroutine(coroutine); coroutine = null; } -} +} \ No newline at end of file diff --git a/Assets/Scripts/Events.meta b/Assets/Scripts/Events.meta index 93ff0e83..682589a1 100644 --- a/Assets/Scripts/Events.meta +++ b/Assets/Scripts/Events.meta @@ -1,5 +1,9 @@ fileFormatVersion: 2 -guid: 1ca7d659c258cfc48be904f4bbdafd0e +<<<<<<< HEAD +guid: 9848fe8237deaf542bdfbaf041b885ae +======= +guid: dd99e40aa78884b4a82e24941c389e05 +>>>>>>> 7af302e5914538fcafa3dceb0b3c8164f4f00ac0 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/Events/EventController.cs b/Assets/Scripts/Events/EventController.cs index 89669c1f..f720f9ae 100644 --- a/Assets/Scripts/Events/EventController.cs +++ b/Assets/Scripts/Events/EventController.cs @@ -1,18 +1,23 @@ using System; - -public class EventController -{ - public event Action baseEvent; - public void InvokeEvent(T type) => baseEvent?.Invoke(type); - public void AddListener(Action listener) => baseEvent += listener; - public void RemoveListener(Action listener) => baseEvent -= listener; -} +using System.Collections; +using System.Collections.Generic; +using UnityEngine; public class EventController { - public event Action baseEvent; + public Action baseEvent; + public void AddListener(Action Listener) => baseEvent += Listener; + + public void RemoveListener(Action Listener) => baseEvent -= Listener; + public void InvokeEvent() => baseEvent?.Invoke(); - public void AddListener(Action listener) => baseEvent += listener; - public void RemoveListener(Action listener) => baseEvent -= listener; } + +public class EventController +{ + public Action baseEvent; + public void AddListener(Action listener) => baseEvent += listener; + public void RemoveListener(Action listener) => baseEvent -= listener; + public void InvokeEvent(T type) => baseEvent?.Invoke(type); +} \ No newline at end of file diff --git a/Assets/Scripts/Events/EventController.cs.meta b/Assets/Scripts/Events/EventController.cs.meta index a3d23e89..538720cb 100644 --- a/Assets/Scripts/Events/EventController.cs.meta +++ b/Assets/Scripts/Events/EventController.cs.meta @@ -1,5 +1,9 @@ fileFormatVersion: 2 +<<<<<<< HEAD guid: 2349e3744fb7a514c8f4dad3859ae586 +======= +guid: 0bc029dcd0768aa458c3576f7406f7c9 +>>>>>>> 7af302e5914538fcafa3dceb0b3c8164f4f00ac0 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/Events/LightsOffByGhostEvent.cs b/Assets/Scripts/Events/LightsOffByGhostEvent.cs index 7ac9a74a..67c70f89 100644 --- a/Assets/Scripts/Events/LightsOffByGhostEvent.cs +++ b/Assets/Scripts/Events/LightsOffByGhostEvent.cs @@ -3,14 +3,13 @@ public class LightsOffByGhostEvent : MonoBehaviour { [SerializeField] private int keysRequiredToTrigger; - [SerializeField] private SoundType soundToPlay; - + [SerializeField] private SoundType soundType; private void OnTriggerEnter(Collider other) { - if (other.GetComponent() != null && GameService.Instance.GetPlayerController().KeysEquipped == keysRequiredToTrigger) + if(other.GetComponent() != null && keysRequiredToTrigger == GameService.Instance.GetPlayerController().KeysEquipped) { EventService.Instance.OnLightsOffByGhostEvent.InvokeEvent(); - GameService.Instance.GetSoundView().PlaySoundEffects(soundToPlay); + GameService.Instance.GetSoundView().PlaySoundEffects(soundType); GetComponent().enabled = false; } } diff --git a/Assets/Scripts/Events/PlayerEscapedEvent.cs b/Assets/Scripts/Events/PlayerEscapedEvent.cs deleted file mode 100644 index de7df07b..00000000 --- a/Assets/Scripts/Events/PlayerEscapedEvent.cs +++ /dev/null @@ -1,15 +0,0 @@ -using UnityEngine; - -public class PlayerEscapedEvent : MonoBehaviour -{ - [SerializeField] private SoundType soundToPlay; - - private void OnTriggerEnter(Collider other) - { - if (other.GetComponent() != null) - { - GameService.Instance.GetSoundView().PlaySoundEffects(soundToPlay); - EventService.Instance.PlayerEscapedEvent.InvokeEvent(); - } - } -} diff --git a/Assets/Scripts/Events/PlayerEscapedEvent.cs.meta b/Assets/Scripts/Events/PlayerEscapedEvent.cs.meta deleted file mode 100644 index 11a5b8a3..00000000 --- a/Assets/Scripts/Events/PlayerEscapedEvent.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ac8787843487b364ab9d933c1a9bb5bd -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Events/RatRushEvent.cs b/Assets/Scripts/Events/RatRushEvent.cs index bb27fdc5..4836ecfc 100644 --- a/Assets/Scripts/Events/RatRushEvent.cs +++ b/Assets/Scripts/Events/RatRushEvent.cs @@ -14,6 +14,7 @@ private void OnTriggerEnter(Collider other) if (other.GetComponent() != null) { onRatRush(); + EventService.Instance.OnRatRush.InvokeEvent(); GameService.Instance.GetSoundView().PlaySoundEffects(soundToPlay); GetComponent().enabled = false; } diff --git a/Assets/Scripts/Events/SkullDropEvent.cs b/Assets/Scripts/Events/SkullDropEvent.cs index 4cd5ec39..e131cc1f 100644 --- a/Assets/Scripts/Events/SkullDropEvent.cs +++ b/Assets/Scripts/Events/SkullDropEvent.cs @@ -11,6 +11,7 @@ private void OnTriggerEnter(Collider other) if (other.GetComponent() != null && GameService.Instance.GetPlayerController().KeysEquipped >= keysRequiredToTrigger) { OnSkullDrop(); + EventService.Instance.OnSkullDrop.InvokeEvent(); GameService.Instance.GetSoundView().PlaySoundEffects(soundToPlay); GetComponent().enabled = false; } diff --git a/Assets/Scripts/Interactables/KeyView.cs b/Assets/Scripts/Interactables/KeyView.cs index 4bb8e94d..88e85139 100644 --- a/Assets/Scripts/Interactables/KeyView.cs +++ b/Assets/Scripts/Interactables/KeyView.cs @@ -11,4 +11,4 @@ public void Interact() EventService.Instance.OnKeyPickedUp.InvokeEvent(++currentKeys); gameObject.SetActive(false); } -} +} \ No newline at end of file diff --git a/Assets/Scripts/Interactables/LightSwitchView.cs b/Assets/Scripts/Interactables/LightSwitchView.cs index 12f841f6..bd66d8e6 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; @@ -6,28 +7,29 @@ public class LightSwitchView : MonoBehaviour, IInteractable [SerializeField] private List lightsources = new List(); [SerializeField] private SoundType soundType; private SwitchState currentState; + public static event Action OnLightSwitchToggled; private void OnEnable() { - EventService.Instance.OnLightSwitchToggled.AddListener(onLightsToggled); - EventService.Instance.OnLightsOffByGhostEvent.AddListener(onLightsOffByGhostEvent); + EventService.Instance.OnLightSwitchToggled.AddListener(onLightSwitch); + EventService.Instance.OnLightsOffByGhostEvent.AddListener(onLightsTurnedOffByGhost); } - private void OnDisable() { EventService.Instance.OnLightSwitchToggled.RemoveListener(onLightsToggled); - EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(onLightsOffByGhostEvent); + EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(onLightsTurnedOffByGhost); } - private void Start() - { - currentState = SwitchState.Off; - } + + private void Start() => currentState = SwitchState.Off; + + public void Interact() { GameService.Instance.GetInstructionView().HideInstruction(); EventService.Instance.OnLightSwitchToggled.InvokeEvent(); } + private void toggleLights() { bool lights = false; @@ -53,21 +55,33 @@ private void toggleLights() private void setLights(bool lights) { + foreach (Light lightSource in lightsources) + { + lightSource.enabled = lights; + } if (lights) + { currentState = SwitchState.On; + } else - currentState = SwitchState.Off; - - foreach (Light lightSource in lightsources) { - lightSource.enabled = lights; + currentState = SwitchState.Off; } } - private void onLightsOffByGhostEvent() + + private void onLightSwitch() + { + toggleLights(); + GameService.Instance.GetSoundView().PlaySoundEffects(SoundType.SwitchSound); + GameService.Instance.GetInstructionView().HideInstruction(); + } + private void onLightsTurnedOffByGhost() { - GameService.Instance.GetSoundView().PlaySoundEffects(soundType); setLights(false); + GameService.Instance.GetSoundView().PlaySoundEffects(SoundType.SwitchSound); + GameService.Instance.GetInstructionView().ShowInstruction(InstructionType.LightsOff); } + private void onLightsToggled() { toggleLights(); diff --git a/Assets/Scripts/Interactables/PotionView.cs b/Assets/Scripts/Interactables/PotionView.cs index 639d68a2..5260a061 100644 --- a/Assets/Scripts/Interactables/PotionView.cs +++ b/Assets/Scripts/Interactables/PotionView.cs @@ -2,13 +2,16 @@ public class PotionView : MonoBehaviour, IInteractable { + [SerializeField] SoundType soundType; private int potionEffect = 20; public void Interact() { + GameService.Instance.GetInstructionView().HideInstruction(); GameService.Instance.GetSoundView().PlaySoundEffects(soundType); + EventService.Instance.OnPotionDrink.InvokeEvent(potionEffect); gameObject.SetActive(false); } } diff --git a/Assets/Scripts/Player/PlayerController.cs b/Assets/Scripts/Player/PlayerController.cs index 709d4f7d..dff638ac 100644 --- a/Assets/Scripts/Player/PlayerController.cs +++ b/Assets/Scripts/Player/PlayerController.cs @@ -1,6 +1,11 @@ +using System.Collections; +using System.Collections.Generic; using UnityEngine; + public class PlayerController { + public bool IsInteracted; + private PlayerView playerView; private PlayerScriptableObject playerScriptableObject; private float velocity; @@ -9,30 +14,32 @@ public class PlayerController private float mouseX; private PlayerState playerState; - public bool IsInteracted; public int KeysEquipped { get => playerScriptableObject.KeysEquipped; set => playerScriptableObject.KeysEquipped = value; } public PlayerState PlayerState { get => playerState; private set => playerState = value; } + public PlayerController(PlayerView playerView, PlayerScriptableObject playerScriptableObject) { this.playerView = playerView; this.playerView.SetController(this); this.playerScriptableObject = playerScriptableObject; this.playerScriptableObject.KeysEquipped = 0; + + playerState = PlayerState.InDark; - EventService.Instance.OnLightsOffByGhostEvent.AddListener(onLightsOffByGhost); - EventService.Instance.OnLightSwitchToggled.AddListener(onLightsToggled); - EventService.Instance.OnKeyPickedUp.AddListener(OnKeyPickedUp); - EventService.Instance.PlayerEscapedEvent.AddListener(DisableControls); + EventService.Instance.OnLightSwitchToggled.AddListener(LightSwitchToggled); + EventService.Instance.OnKeyPickedUp.AddListener(onKeysPickedUp); + EventService.Instance.OnLightsOffByGhostEvent.AddListener(onLightsTurnedOffByGhost); } + ~PlayerController() { - EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(onLightsOffByGhost); - EventService.Instance.OnLightSwitchToggled.RemoveListener(onLightsToggled); - EventService.Instance.OnKeyPickedUp.RemoveListener(OnKeyPickedUp); - EventService.Instance.PlayerEscapedEvent.RemoveListener(DisableControls); + EventService.Instance.OnLightSwitchToggled.RemoveListener(LightSwitchToggled); + EventService.Instance.OnKeyPickedUp.RemoveListener(onKeysPickedUp); + EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(onLightsTurnedOffByGhost); } + public void Interact() => IsInteracted = Input.GetKeyDown(KeyCode.E) ? true : (Input.GetKeyUp(KeyCode.E) ? false : IsInteracted); public void Jump(Rigidbody playerRigidbody, Transform transform) @@ -47,7 +54,7 @@ public void Jump(Rigidbody playerRigidbody, Transform transform) public void Move(Rigidbody playerRigidbody, Transform transform) { - getInput(); + GetInput(); Quaternion rotation; Vector3 position; @@ -60,14 +67,9 @@ public void Move(Rigidbody playerRigidbody, Transform transform) public void KillPlayer() { PlayerState = PlayerState.Dead; - EventService.Instance.PlayerDeathEvent.InvokeEvent(); } - private void onLightsOffByGhost() => PlayerState = PlayerState.InDark; - private void OnKeyPickedUp(int keys) => KeysEquipped = keys; - private void DisableControls() => playerView.enabled = false; - - private void getInput() + private void GetInput() { horizontalAxis = Input.GetAxis("Horizontal"); verticalAxis = Input.GetAxis("Vertical"); @@ -82,11 +84,23 @@ private void calculatePositionRotation(Rigidbody playerRigidbody, Transform tran rotation = playerRigidbody.rotation * Quaternion.Euler(lookRotation); position = (transform.position) + (velocity * movement) * Time.fixedDeltaTime; } - private void onLightsToggled() + private void LightSwitchToggled() { if (PlayerState == PlayerState.InDark) + { PlayerState = PlayerState.None; + } else + { PlayerState = PlayerState.InDark; + } + } + + private void onLightsTurnedOffByGhost() => PlayerState = PlayerState.InDark; + + + private void onKeysPickedUp(int keys) + { + KeysEquipped = keys; } -} +} \ No newline at end of file diff --git a/Assets/Scripts/Player/PlayerSanity.cs b/Assets/Scripts/Player/PlayerSanity.cs index 6eb89bef..39492204 100644 --- a/Assets/Scripts/Player/PlayerSanity.cs +++ b/Assets/Scripts/Player/PlayerSanity.cs @@ -4,15 +4,28 @@ public class PlayerSanity : MonoBehaviour { [SerializeField] private float sanityLevel = 100.0f; [SerializeField] private float sanityDropRate = 0.2f; - [SerializeField] private float sanityDropAmountPerEvent = 10f; + private float maxSanity; private PlayerController playerController; + private void OnEnable() + { + EventService.Instance.OnRatRush.AddListener(OnSupernaturalEvent); + EventService.Instance.OnSkullDrop.AddListener(OnSupernaturalEvent); + EventService.Instance.OnPotionDrink.AddListener(OnDrankPotion); + } + private void OnDisable() + { + EventService.Instance.OnRatRush.RemoveListener(OnSupernaturalEvent); + EventService.Instance.OnSkullDrop.RemoveListener(OnSupernaturalEvent); + EventService.Instance.OnPotionDrink.RemoveListener(OnDrankPotion); + } private void Start() { maxSanity = sanityLevel; playerController = GameService.Instance.GetPlayerController(); } + void Update() { if (playerController.PlayerState == PlayerState.Dead) @@ -55,11 +68,12 @@ private void decreaseSanity(float amountToIncrease) } private void OnSupernaturalEvent() { - increaseSanity(sanityDropAmountPerEvent); + increaseSanity(sanityDropRate); } private void OnDrankPotion(int potionEffect) { decreaseSanity(potionEffect); } + } \ No newline at end of file diff --git a/Assets/Scripts/Player/PlayerView.cs b/Assets/Scripts/Player/PlayerView.cs index 10f8011c..a0777411 100644 --- a/Assets/Scripts/Player/PlayerView.cs +++ b/Assets/Scripts/Player/PlayerView.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; +using UnityEngine; [RequireComponent(typeof(Rigidbody))] public class PlayerView : MonoBehaviour diff --git a/Assets/Scripts/Service/EventService.cs b/Assets/Scripts/Service/EventService.cs index fdb347e8..d73ca7c3 100644 --- a/Assets/Scripts/Service/EventService.cs +++ b/Assets/Scripts/Service/EventService.cs @@ -1,3 +1,9 @@ + +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + public class EventService { private static EventService instance; @@ -17,16 +23,28 @@ public static EventService Instance public EventController OnKeyPickedUp { get; private set; } public EventController OnLightsOffByGhostEvent { get; private set; } - public EventController PlayerEscapedEvent { get; private set; } - public EventController PlayerDeathEvent { get; private set; } + public EventController OnPlayerEscapedEvent { get; private set; } + public EventController OnPlayerDeathEvent { get; private set; } + + public EventController OnRatRush { get; private set; } + + public EventController OnSkullDrop { get; private set; } + + public EventController OnPotionDrink { get; private set; } + + public EventService() { OnLightSwitchToggled = new EventController(); OnKeyPickedUp = new EventController(); OnLightsOffByGhostEvent = new EventController(); + OnRatRush = new EventController(); + OnPlayerEscapedEvent = new EventController(); + OnPlayerDeathEvent = new EventController(); + OnSkullDrop = new EventController(); + OnPotionDrink = new EventController(); - PlayerEscapedEvent = new EventController(); - PlayerDeathEvent = new EventController(); } } + diff --git a/Assets/Scripts/Service/EventService.cs.meta b/Assets/Scripts/Service/EventService.cs.meta index b2b3c2a4..7d51622d 100644 --- a/Assets/Scripts/Service/EventService.cs.meta +++ b/Assets/Scripts/Service/EventService.cs.meta @@ -1,5 +1,9 @@ fileFormatVersion: 2 +<<<<<<< HEAD guid: e31cd314a935b6d4f87c18700006968c +======= +guid: 1e8354395b6d60748b4f1366e990b284 +>>>>>>> 7af302e5914538fcafa3dceb0b3c8164f4f00ac0 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/Service/GameService.cs b/Assets/Scripts/Service/GameService.cs index d0e7a6ab..9992c64f 100644 --- a/Assets/Scripts/Service/GameService.cs +++ b/Assets/Scripts/Service/GameService.cs @@ -18,9 +18,6 @@ public class GameService : GenericMonoSingleton private void Start() => playerController = new PlayerController(playerView, playerScriptableObject); - //Todo - Ask Mayank -> Converting all these into properties as {get;private set;} is good or - // we can keep it same for now? - public PlayerController GetPlayerController() => playerController; public GameUIView GetGameUI() => gameUIView; public InstructionView GetInstructionView() => instructionView; diff --git a/Assets/Scripts/UI/GameUIView.cs b/Assets/Scripts/UI/GameUIView.cs index 01c49482..5189f07a 100644 --- a/Assets/Scripts/UI/GameUIView.cs +++ b/Assets/Scripts/UI/GameUIView.cs @@ -21,47 +21,64 @@ public class GameUIView : MonoBehaviour private void OnEnable() { - EventService.Instance.OnKeyPickedUp.AddListener(OnKeyEquipped); - EventService.Instance.OnLightsOffByGhostEvent.AddListener(SetRedVignette); - EventService.Instance.PlayerEscapedEvent.AddListener(OnPlayerEscaped); - EventService.Instance.PlayerDeathEvent.AddListener(SetRedVignette); - EventService.Instance.PlayerDeathEvent.AddListener(OnPlayerDeath); - - tryAgainButton.onClick.AddListener(OnTryAgainButtonClicked); - quitButton.onClick.AddListener(OnQuitButtonClicked); + + tryAgainButton.onClick.AddListener(onTryAgainButtonClicked); + quitButton.onClick.AddListener(onQuitButtonClicked); + EventService.Instance.OnKeyPickedUp.AddListener(updateKeyText); + EventService.Instance.OnLightsOffByGhostEvent.AddListener(setRedVignette); + + EventService.Instance.OnPlayerEscapedEvent.AddListener(onPlayerEscaped); + EventService.Instance.OnPlayerDeathEvent.AddListener(setRedVignette); + EventService.Instance.OnPlayerDeathEvent.AddListener(onPlayerDeath); + EventService.Instance.OnRatRush.AddListener(setRedVignette); + EventService.Instance.OnSkullDrop.AddListener(setRedVignette); + + + tryAgainButton.onClick.AddListener(onTryAgainButtonClicked); + quitButton.onClick.AddListener(onQuitButtonClicked); } private void OnDisable() { - EventService.Instance.OnKeyPickedUp.RemoveListener(OnKeyEquipped); - EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(SetRedVignette); - EventService.Instance.PlayerEscapedEvent.RemoveListener(OnPlayerEscaped); - EventService.Instance.PlayerDeathEvent.RemoveListener(SetRedVignette); - EventService.Instance.PlayerDeathEvent.RemoveListener(OnPlayerDeath); - } + EventService.Instance.OnKeyPickedUp.RemoveListener(updateKeyText); + EventService.Instance.OnLightsOffByGhostEvent?.RemoveListener(setRedVignette); + EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(setRedVignette); + EventService.Instance.OnPlayerEscapedEvent.RemoveListener(onPlayerEscaped); + EventService.Instance.OnPlayerDeathEvent.RemoveListener(setRedVignette); + EventService.Instance.OnPlayerDeathEvent.RemoveListener(onPlayerDeath); + EventService.Instance.OnRatRush.RemoveListener(setRedVignette); + EventService.Instance.OnSkullDrop.RemoveListener(setRedVignette); + + } public void UpdateInsanity(float playerSanity) => insanityImage.rectTransform.localScale = new Vector3(1, playerSanity, 1); - private void OnKeyEquipped(int keys) => keysFoundText.SetText($"Keys Found: {keys}/3"); - private void OnQuitButtonClicked() => Application.Quit(); - private void OnTryAgainButtonClicked() => SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); + private void updateKeyText(int keys) => keysFoundText.SetText($"Keys Found: {keys}/3"); - private void SetRedVignette() + private void onQuitButtonClicked() => Application.Quit(); + private void onTryAgainButtonClicked() => SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); + + + + //Assignment - Call this method as a lister of LightsOffByGhostEvent + private void setRedVignette() { redVignette.enabled = true; redVignette.canvasRenderer.SetAlpha(0.5f); redVignette.CrossFadeAlpha(0, 5, false); } - private void OnPlayerDeath() + private void onPlayerDeath() { gameEndText.SetText("Game Over"); gameEndPanel.SetActive(true); } - private void OnPlayerEscaped() + private void onPlayerEscaped() { gameEndText.SetText("You Escaped"); - gameEndPanel.SetActive(true); + gameEndPanel.SetActive(false); } + + } diff --git a/Assets/Scripts/UI/Instruction/InstructionView.cs b/Assets/Scripts/UI/Instruction/InstructionView.cs index e847873c..b1d0f7da 100644 --- a/Assets/Scripts/UI/Instruction/InstructionView.cs +++ b/Assets/Scripts/UI/Instruction/InstructionView.cs @@ -17,8 +17,7 @@ public class InstructionView : MonoBehaviour private Coroutine instructionCoroutine; private void Start() => showInstruction(playerSpawnedInstruction); - private void OnEnable() => EventService.Instance.OnLightsOffByGhostEvent.AddListener(showLightOffInstructions); - private void OnDisable() => EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(showLightOffInstructions); + public void ShowInstruction(InstructionType type) { @@ -69,15 +68,9 @@ private void stopCoroutine(Coroutine coroutine) coroutine = null; } } - - private void showLightOffInstructions() - { - ShowInstruction((InstructionType.LightsOff)); - } - private void showInstruction(InstructionSciprtableObject instruction) { stopCoroutine(instructionCoroutine); instructionCoroutine = StartCoroutine(setInstructions(instruction)); } -} +} \ No newline at end of file diff --git a/Assets/Scripts/UI/MainMenuUIView.cs b/Assets/Scripts/UI/MainMenuUIView.cs index fb52ad62..c7ee1763 100644 --- a/Assets/Scripts/UI/MainMenuUIView.cs +++ b/Assets/Scripts/UI/MainMenuUIView.cs @@ -5,7 +5,6 @@ public class MainMenuUIView : MonoBehaviour { [SerializeField] private Button playButton; - private void OnEnable() => playButton.onClick.AddListener(OnPlayButtonClicked); private void OnPlayButtonClicked() => SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1); }