首页 > 编程知识 正文

unity 生命周期,unity无窗口运行

时间:2023-05-06 10:10:21 阅读:171168 作者:1516

Time.timeScale=0可以暂停游戏,Time.timeScale=1恢复正常。 暂停内容包括动画、特殊效果、UI动画等

如果设置Time.timeScale=0,则与帧速率无关的所有事情都会暂停。 这些主要是指所有物理事件和依赖于时间的函数、刚体力和速度等。 然后,固定更新会受到影响并暂停(而不是更新)。 这意味着如果timeScale=0,则不调用固定更新函数。 timeScale不影响Update和LateUpdate的运行速度。 “FixedUpdate”是基于时间的,因此“timeScale”只影响“FixedUpdate”的速度。

游戏暂停后,如果希望暂停界面继续进行不受Time.timeScale影响的动画、粒子效果等,则需要使用Time.realtimeSinceStartup分别恢复他们。 另外,语音部分也需要单独恢复timeScale

如何使游戏中的某个游戏对象不受Time.timeScale的影响

动画(animationsignoretimescale-unity answers ) staticienumeratorplay ) animation,string clipName,bool use time bool isPlaying=true; float _startTime=0F; float _progressTime=0F; float _timeAtLastFrame=0F; float _timeAtCurrentFrame=0F; float deltaTime=0F; animation.play(clipname; _ timeatlastframe=time.realtimesincestartup; while (is playing (_ timeatcurrentframe=time.realtimesincestartup; delta time=_ timeatcurrentframe-_ timeatlastframe; _ timeatlastframe=_ timeatcurrentframe; _progressTime =deltaTime; _ curr state.normalized time=_ progress time/_ curr state.length; animation.Sample (; 进程时间=_ curr state.length (if ) _currstate.wrapmode!=wrapmode.loop(isplaying=false; }else{_progressTime=0.0f; } yieldreturnnewwaitforendofframe (; }yield return null; if (完成!=null () {onComplete; }else{animation.play(clipname ); }粒子的特殊效果不受timescale的影响(https://gist.github.com/Alex titanium/5676482 );using UnityEngine; using System.Collections; publicclassparticaleanimator : mono behaviour { privatevoidawake (} { particle=getcomponentparticlesystem ); //usethisforinitializationvoidstart () last time=time.realtimesincestartup; //updateiscalledonceperframevoidupdate () floatdeltatime=time.realtimesincestartup-(float ) lastTime; particle.simulate(deltatime,true,false ); //last must be false! last time=time.realtimesincestartup; } private double lastTime; 私有粒子系统粒子; }声音忽略由audiosourcesource=game object.addcomponentaudiosource (; //设定播放声音的速度。 默认速度为1。 加速后,应该是time.timescales ource.pitch=ignore time scale吗? 1:Time.timeScale; //声音source.Play (; 遍历所有音频对象

publicstaticvoidtimescalechanged () foreach ) audiosourceinsoundlist.keys ) if ) source!=null } { source.pitch=sound list [ source ]? 1:Time.timeScale; } }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。