[英]How do I manipulate Time.timeScale with the character controller?
我正在尝试做类似原型游戏SuperHot的事情,其中“时间只有在移动时移动”。
我能想到的方法包括使用输入或字符控制器的速度来操纵Time.timeScale。
以下是我的操作方法:
using UnityEngine;
using System.Collections;
public class TimeMechanic : MonoBehaviour {
private float targetScale;
// Use this for initialization
void Start ()
{
targetScale = 0.02f;
}
// Update is called once per frame
void Update ()
{
Time.timeScale = targetScale; //setting the timeScale
if (Input.GetAxis ("Horizontal") != 0 || Input.GetAxis ("Vertical") != 0)
{
targetScale += 0.03f; //incrementing the variable by 0.03
if (targetScale > 1f)
{
targetScale = 1f; //limits the variable to 1 at max
}
}
else
{
targetScale -= 0.03f; //decrementing the variable by 0.03
if (targetScale < 0.02f)
{
targetScale = 0.02f; //limits variable to 0.02 at min
}
}
Debug.Log (targetScale);
}
}
我的问题:
这将取决于您的算法。 实际上,当您减少timeScale
,它将具有循环依赖性。 取决于Input
会更好,但这取决于您期望的外观。
当timeScale设置为零时,如果您所有功能均与帧速率无关,则游戏基本上会暂停。
除了realtimeSinceStartup之外,timeScale影响Time类的所有时间和增量时间测量变量。
如果降低timeScale,建议也将Time.fixedDeltaTime降低相同的量。
当timeScale设置为零时,将不会调用FixedUpdate函数。
由于Physics
是最有优先FixedUpdate
既要注意以上几点,除非你的游戏有很多违规行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.