H_SafeExperienceDrivingSystem/U3D_DrivingSystem/Assets/Script/DianDongCheManager.cs

50 lines
1.2 KiB
C#

using System;
using System.Collections;
using UnityEngine;
namespace Script
{
public class DianDongCheManager : MonoBehaviour
{
public static DianDongCheManager Instance;
private bool isPaused = false;
public Animation anim;
private void Awake()
{
Instance = this;
}
public IEnumerator PauseAndResumeAnimation()
{
if (!isPaused)
{
isPaused = true; // 设置暂停标志
// 暂停动画
foreach (AnimationState state in anim)
{
state.speed = 0;
}
yield return new WaitForSeconds(3); // 等待三秒钟
// 继续播放动画
foreach (AnimationState state in anim)
{
state.speed = 1;
}
isPaused = false; // 重置暂停标志
}
// 如果已经暂停,这里什么也不做
}
// 你可以从其他方法中调用这个方法
public void ControlAnimation()
{
StartCoroutine(PauseAndResumeAnimation());
}
}
}