unity动画特效不受timeScale影响

2022-07-31,,,,

跑酷类游戏会用TimeScale来控制游戏的节奏,当timeScale不为1时,动画特效播放会受到影响,因此需要写一些脚本去控制动画特效的播放
以下是ParticleSystem的控制类,后续补充Animation和Animator的

思路: Time.unscaledDeltaTime 不受timeScale影响
扩展: 协程yield return new WaitForSeconds也会受到影响,可以改为使用yield return new WaitForSecondsRealtime


ParticleSystem的控制类:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ParticleSystemCtrl : MonoBehaviour
{
	ParticleSystem[] list;

	void Awake()
	{
		Time.timeScale = 0;
		list = GetComponentsInChildren<ParticleSystem>();
	}

	private void Update()
	{
		if (list != null && list.Length > 0)
		{
			foreach (var item in list)
			{
				item.Simulate(Time.unscaledDeltaTime, true, false);
			}
		}
	}

}

本文地址:https://blog.csdn.net/qq_34937637/article/details/107900684

《unity动画特效不受timeScale影响.doc》

下载本文的Word格式文档,以方便收藏与打印。