简体   繁体   English

放慢时间Unity3d Mecanim

[英]Slow down time Unity3d Mecanim

I am trying to slow down and ultimately stop it, i have a script that slows down timeScale however with that my player using mecanim also slows down. 我试图放慢速度并最终停止它,我有一个放慢timeScale的脚本,但是使用mecanim的播放器也放慢了速度。

I have created a TimeController.cs that will allow me to keep track of time by having a alternative deltaTime as the player can use for variable, 我创建了一个TimeController.cs,通过使用替代的deltaTime,玩家可以使用它来跟踪时间,

public class TimeController : MonoBehaviour {

private float oldTimeSinceStart;
public float deltaTime;

void LateUpdate () {
    float timeSinceStart = Time.realtimeSinceStartup;
    deltaTime = timeSinceStart - oldTimeSinceStart;
    oldTimeSinceStart = timeSinceStart;

    if (Input.GetButton("BulletTime"))
    {
        if (Time.timeScale > 0.01)
        {
            Time.timeScale -= 0.004f;
        }
    }
    else
    {
        if (Time.timeScale < 1)
        {
            Time.timeScale += 0.01f;
        }
    }
}
}

From this point i thought about using Animator Update to set the mecanim logic driven speed for player speed and animation speed, however i dont seem to be able, When using Animator.Update(MyTimeController.deltaTime); 从这一点出发,我考虑过使用Animator Update来设置mecanim逻辑驱动的播放器速度和动画速度,但是当使用Animator.Update(MyTimeController.deltaTime)时,我似乎无法做到。 It seems to run at variable speed, as if the Animator has a second input somewhere. 它似乎以可变速度运行,好像Animator在某处有第二个输入。

is there away around this? 有没有解决的办法? can you isolate the timeScale from the player/mecanim and have it look at another Time class for input variables? 您可以将timeScale与播放器/ mecanim隔离开来,并让其查看输入变量的另一个Time类吗?

So time slows down for the world but not the player, think clockstoppers! 因此,对于世界来说,时间在变慢,但对于玩家而言,却变慢了,想想时钟停止器吧!

Acording to Unity Documentation there's this animation speed property in the animator object: 根据Unity文档,动画师对象中具有以下动画速度属性:

https://docs.unity3d.com/Documentation/ScriptReference/Animator-speed.html https://docs.unity3d.com/Documentation/ScriptReference/Animator-speed.html

Try using <yourgameobjecthere>.getComponent<Animator>().speed = Time.timescale; 尝试使用<yourgameobjecthere>.getComponent<Animator>().speed = Time.timescale; right after you set the time scale. 在设置时间刻度之后。

I'm not sure the animation speed is applied correctly during an animation tho. 我不确定在动画播放过程中是否正确应用了动画速度。

As Felype mentioned, you can use Animator Component, I usually get the Animator component and then use <animator_object>[<animation_clip_object.name>] .speed. 正如Felype所述,您可以使用Animator组件,我通常会获得Animator组件,然后使用<animator_object>[<animation_clip_object.name>] .speed。 For speed, value of 1 means normal speed. 对于速度,值1表示正常速度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM