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>();
|
|
|
|
|
2023-10-05 17:56:59 +03:00
|
|
|
public bool AutoAction = false;
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
if (AutoAction)
|
|
|
|
{
|
|
|
|
ActivateVisor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-11 15:44:17 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-18 20:09:22 +03:00
|
|
|
[ContextMenu("Debug activate")]
|
2023-09-11 15:44:17 +03:00
|
|
|
private void ActivateVisor()
|
|
|
|
{
|
|
|
|
_visorActivated = true;
|
|
|
|
OnActivated?.Invoke();
|
|
|
|
}
|
|
|
|
}
|