Pauser Added + Fixed Bug
TODO: Stop Animations when Paused
This commit is contained in:
40
Assets/Scripts/Pausable/Pauser.cs
Normal file
40
Assets/Scripts/Pausable/Pauser.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Level;
|
||||
using UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Pausable
|
||||
{
|
||||
public class Pauser : MonoBehaviour
|
||||
{
|
||||
protected Input.PlayerInput playerInput = null;
|
||||
protected bool isPaused = false;
|
||||
|
||||
protected void Start()
|
||||
{
|
||||
playerInput = new Input.PlayerInput();
|
||||
playerInput.Enable();
|
||||
playerInput.PlayerControl.Pause.performed += (context) => TogglePause();
|
||||
}
|
||||
|
||||
public void TogglePause()
|
||||
{
|
||||
if (LevelManager.Instance.CurrentLevel == null)
|
||||
return;
|
||||
|
||||
isPaused = !isPaused;
|
||||
|
||||
if (isPaused)
|
||||
UIManager.Instance.SwitchToCanvas("Pause Menu");
|
||||
else
|
||||
UIManager.Instance.CloseAllCanvases();
|
||||
|
||||
foreach (IPausable pausable in FindObjectsOfType<MonoBehaviour>().OfType<IPausable>())
|
||||
if (isPaused)
|
||||
pausable.Pause();
|
||||
else
|
||||
pausable.Resume();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Pausable/Pauser.cs.meta
Normal file
11
Assets/Scripts/Pausable/Pauser.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1705d06bcf3cabe4d9e2614e86cd0561
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user