using System.Collections; using System.Collections.Generic; using UnityEngine; namespace UltraCombos { public class ImageFader : MonoBehaviour { CanvasGroup canvas_group; float fade_stamp; AnimationCurve curve; bool is_active = true; const float fading = 0.3f; const float eps = 0.5f / 255.0f; private void Start() { canvas_group = GetComponent(); if (canvas_group == null) canvas_group = gameObject.AddComponent(); canvas_group.alpha = 1.0f; curve = AnimationCurve.EaseInOut(0, 0, 1, 1); SetActive(false); } private void FixedUpdate() { float a = canvas_group.alpha; float b = is_active ? 1 : 0; if (Mathf.Abs(a - b) < eps) { canvas_group.alpha = b; } else { float t = Time.fixedDeltaTime * 8.0f; canvas_group.alpha = Mathf.Lerp(a, b, t); } } public void SetActive(bool value) { fade_stamp = Time.time; is_active = canvas_group.blocksRaycasts = canvas_group.interactable = value; } } }