unity3D 粒子特效播放受TimeScale影响

2015-12-30 雨辰 Unity3D

  /// <summary>
        /// 粒子效果 Animator 是否受游戏暂停影响
        /// </summary>
        public bool ignoreTimeScale = true; 
        float lastTime = 0;
        void Update()
        {
            if (effectObj != null && !ignoreTimeScale)
            {
                ParticleSystem[] particles = effectObj.GetComponentsInChildren<ParticleSystem>();
                if (particles != null && particles.Length > 0)
                {
                    float deltaTime = Time.realtimeSinceStartup - (float)lastTime;
                    foreach (ParticleSystem particle in particles)
                    {
                        particle.Simulate(deltaTime, true, false);
                    }
                    lastTime = Time.realtimeSinceStartup;
                }
            }
        }

 

标签: Unity3D

发表评论:

雨辰 joyimp|@2011-2018 京ICP备16030765号