using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [Serializable] public class Combination { public string description; public List buttons; [SerializeField] UnityEvent OnActivated; private Image timerImage; float pressedTime = 0; float timeToGo = 1.5f; public bool Process() { timerImage.fillAmount = pressedTime / timeToGo; bool condition = checkCondition(); if (condition) { pressedTime += Time.deltaTime; if (pressedTime >= timeToGo) { OnActivated?.Invoke(); pressedTime = 0; } } else { pressedTime -= Time.deltaTime; pressedTime = Mathf.Clamp(pressedTime, 0, timeToGo); } return condition; } private bool checkCondition() { bool res = true; foreach (ButtonPinMapping button in buttons) { res = res && In.GetButton(button); } return res; } public void SetImageLink(Image image) => timerImage = image; }