rabidus-test/Assets/Scripts/VisorUIModule.cs

62 lines
1.4 KiB
C#
Raw Permalink Normal View History

2023-08-15 17:38:54 +03:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class VisorUIModule : MonoBehaviour
{
[SerializeField]
private CanvasGroup _mainPanel;
[SerializeField]
private CanvasGroup _tutorPanel;
[SerializeField]
private Image _progressBarImage;
2023-08-22 15:41:12 +03:00
2023-08-15 17:38:54 +03:00
public InputActionReference LeftTrigger;
public InputActionReference RightTrigger;
private float _visibleValue = 0;
private bool _visorActivated = false;
public UnityEvent OnVisorActivated = new UnityEvent();
private void Update()
{
if (_visorActivated)
return;
if (RightTrigger.action.inProgress && LeftTrigger.action.inProgress)
{
_visibleValue = Mathf.Clamp01(_visibleValue + Time.deltaTime);
}
else
{
_visibleValue = Mathf.Clamp01(_visibleValue - Time.deltaTime);
}
UpdateVisorValue();
}
private void UpdateVisorValue()
{
_mainPanel.alpha = _visibleValue;
_tutorPanel.alpha = 1 - _visibleValue;
_progressBarImage.fillAmount = _visibleValue;
if (_visibleValue == 1)
{
ActivateVisor();
}
}
private void ActivateVisor()
{
_visorActivated = true;
OnVisorActivated?.Invoke();
}
2023-08-22 15:41:12 +03:00
}