using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace CurvedUI { public class CUI_ChangeValueOnHold : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IEventSystemHandler { private bool pressed; private bool selected; [SerializeField] private Image bg; [SerializeField] private Color SelectedColor; [SerializeField] private Color NormalColor; [SerializeField] private CanvasGroup IntroCG; [SerializeField] private CanvasGroup MenuCG; private void Update() { pressed = Input.GetKey(KeyCode.Space) || Input.GetButton("Fire1"); ChangeVal(); } private void ChangeVal() { if (GetComponent().normalizedValue == 1f) { IntroCG.alpha -= Time.deltaTime; MenuCG.alpha += Time.deltaTime; } else { GetComponent().normalizedValue += ((!pressed || !selected) ? (0f - Time.deltaTime) : Time.deltaTime); } IntroCG.blocksRaycasts = IntroCG.alpha > 0f; } public void OnPointerEnter(PointerEventData data) { bg.color = SelectedColor; bg.GetComponent().TesselationRequired = true; selected = true; } public void OnPointerExit(PointerEventData data) { bg.color = NormalColor; bg.GetComponent().TesselationRequired = true; selected = false; } } }