Cute_demon_attacks/meng_yao/Assets/script/A_Fight/ScreenFlashEffect.cs
2024-12-25 15:39:40 +08:00

49 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class ScreenFlashEffect : MonoBehaviour
{
public Image screenEdgeImage; // 用于显示闪烁的UI元素整个屏幕的边缘效果
public float flashDuration = 1f; // 每次闪烁的持续时间
public Color flashColor = new Color(1f, 0f, 0f, 0.5f); // 红色透明的渐变颜色
public float flashInterval = 1f; // 闪烁间隔比如每隔0.5秒闪烁一次)
void Update()
{
}
private void Start()
{
// 初始化透明状态
screenEdgeImage.color = new Color(0, 0, 0, 0); // 初始透明
}
public void StartFlashing()
{
// 使用DOTween做循环闪烁动画
Sequence sequence = DOTween.Sequence();
// 1. 渐变到红色
sequence.Append(screenEdgeImage.DOColor(flashColor, flashDuration).SetEase(Ease.InOutQuad));
// 2. 再渐变回透明
sequence.Append(screenEdgeImage.DOColor(new Color(0, 0, 0, 0), flashDuration).SetEase(Ease.InOutQuad));
// 3. 循环闪烁
//sequence.SetLoops(-1, LoopType.Yoyo); // 无限次循环往返动画Yoyo
}
public void StopFlashing()
{
// 取消闪烁效果
screenEdgeImage.color = new Color(0, 0, 0, 0); // 恢复透明
DOTween.Kill(screenEdgeImage); // 停止所有DOTween动画
}
}