rabidus-test/Assets/Scripts/DoubleTriggerAction.cs

51 lines
1.1 KiB
C#
Raw Normal View History

2023-09-11 15:44:17 +03:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
public class DoubleTriggerAction : MonoBehaviour
{
public InputActionReference LeftTrigger;
public InputActionReference RightTrigger;
private float _currentValue = 0;
private bool _visorActivated = false;
public UnityEvent OnActivated = new UnityEvent();
public UnityEvent<float> OnValueChanged = new UnityEvent<float>();
private void Update()
{
if (_visorActivated)
return;
if (RightTrigger.action.inProgress && LeftTrigger.action.inProgress)
{
_currentValue = Mathf.Clamp01(_currentValue + Time.deltaTime);
}
else
{
_currentValue = Mathf.Clamp01(_currentValue - Time.deltaTime);
}
UpdateVisorValue();
}
private void UpdateVisorValue()
{
OnValueChanged?.Invoke(_currentValue);
if (_currentValue == 1)
{
ActivateVisor();
}
}
private void ActivateVisor()
{
_visorActivated = true;
OnActivated?.Invoke();
}
}