2026-01-12 09:36:17 +03:00

86 lines
2.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class RulesEffect : MonoBehaviour, IEffect
{
[SerializeField] List<Graphic> cards;
[SerializeField] AudioClip cardAppearClip;
[SerializeField] Graphic label;
public float delayBetweenCards = 0.5f;
public float appearDuration = 1f;
public float cardStandTime = 2f;
public float disappearDuration = 1f;
public void Play()
{
//карточки
for (int i = 0; i < cards.Count; i++)
{
StartCoroutine(ShowGraphic(graphic: cards[i],
delay: delayBetweenCards * i,
appearDuration: appearDuration,
standTime: cardStandTime,
disappearDuration: disappearDuration));
}
//текст 4.5 сек всего
StartCoroutine(ShowGraphic(graphic: label,
delay: 0,
appearDuration: appearDuration,
standTime: cardStandTime,
disappearDuration: disappearDuration));
}
IEnumerator ShowGraphic(Graphic graphic, float delay, float appearDuration, float standTime, float disappearDuration)
{
if (graphic == null) yield break;
yield return new WaitForSeconds(delay);
graphic.gameObject.SetActive(true);
Color c = graphic.color;
float startAlpha = 0;
float targetAlpha = 1;
float t = 0;
while (t != 1)
{
c.a = Mathf.Lerp(startAlpha, targetAlpha, t);
graphic.color = c;
t = Mathf.Clamp01(t + Time.deltaTime / appearDuration);
yield return null;
}
yield return new WaitForSeconds(standTime);
startAlpha = 1;
targetAlpha = 0;
t = 0;
while (t != 1)
{
c.a = Mathf.Lerp(startAlpha, targetAlpha, t);
graphic.color = c;
t = Mathf.Clamp01(t + Time.deltaTime / disappearDuration);
yield return null;
}
graphic.gameObject.SetActive(false);
}
}