116 lines
2.8 KiB
C#
116 lines
2.8 KiB
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class PlayerStatusManager : MonoBehaviour
|
|
{
|
|
public static PlayerStatusManager Instance { get; private set;}
|
|
|
|
[SerializeField] private InputActionProperty zlButtonAction;
|
|
[SerializeField] private InputActionProperty zrButtonAction;
|
|
|
|
[SerializeField] private float maxGauge = 100f;
|
|
[SerializeField] private float currentGauge = 0f;
|
|
|
|
[SerializeField] private GameObject codingModeUI;
|
|
|
|
private bool isCodingMode = false;
|
|
|
|
void Awake()
|
|
{
|
|
if(Instance == null)
|
|
{
|
|
Instance = this;
|
|
}
|
|
else
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if(zlButtonAction.action != null) zlButtonAction.action.Enable();
|
|
if(zrButtonAction.action != null) zrButtonAction.action.Enable();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if(zlButtonAction.action != null) zlButtonAction.action.Disable();
|
|
if(zrButtonAction.action != null) zrButtonAction.action.Disable();
|
|
}
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
if(codingModeUI != null)
|
|
{
|
|
codingModeUI.SetActive(false);
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
CheckComboInput();
|
|
}
|
|
|
|
public void AddGauge(float amout)
|
|
{
|
|
if(isCodingMode) return;
|
|
|
|
currentGauge += amout;
|
|
currentGauge = Mathf.Clamp(currentGauge, 0f, maxGauge);
|
|
}
|
|
|
|
private void CheckComboInput()
|
|
{
|
|
if(zlButtonAction.action == null || zrButtonAction.action ==null) return;
|
|
|
|
bool zlPressed = zlButtonAction.action.triggered && zlButtonAction.action.ReadValue<float>() > 0.5f;
|
|
bool zrPressed = zlButtonAction.action.triggered && zrButtonAction.action.ReadValue<float>() > 0.5f;
|
|
|
|
if(!isCodingMode && currentGauge >= maxGauge)
|
|
{
|
|
if((zlPressed && zrButtonAction.action.ReadValue<float>() > 0.5f) ||
|
|
(zrPressed && zlButtonAction.action.ReadValue<float>() > 0.5f))
|
|
{
|
|
StartCodingMode();
|
|
}
|
|
}
|
|
else if(isCodingMode)
|
|
{
|
|
if((zlPressed && zrButtonAction.action.ReadValue<float>() > 0.5f) ||
|
|
(zrPressed && zlButtonAction.action.ReadValue<float>() > 0.5f))
|
|
{
|
|
EndCodingMode();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void StartCodingMode()
|
|
{
|
|
isCodingMode = true;
|
|
|
|
Time.timeScale = 0f;
|
|
|
|
if(codingModeUI != null)
|
|
{
|
|
codingModeUI.SetActive(true);
|
|
}
|
|
}
|
|
|
|
private void EndCodingMode()
|
|
{
|
|
isCodingMode = false;
|
|
|
|
Time.timeScale = 1f;
|
|
|
|
if(codingModeUI != null)
|
|
{
|
|
codingModeUI.SetActive(false);
|
|
}
|
|
|
|
currentGauge = 0f;
|
|
}
|
|
}
|