unity3d 怎么做游戏暂停弹窗

发布网友 发布时间:2022-04-22 09:43

我来回答

2个回答

热心网友 时间:2023-06-24 17:06

简单点来说,控制Time.timeScale=0就让时间静止了,此时你写一个GUI弹出来即可

复杂的话,你需要设置一个暂停系统,控制各种可以动的对象,通过发送bool而使他们运动和停止

希望对你有帮助,望采纳追问你好,可能我没有问明白,而且还有一些后续的问题,能留个qq说吗?谢了!

热心网友 时间:2023-06-24 17:06

Time.timeScale = value;value 为0时,游戏就暂停了,为1时就是正常速度。但是实例化的对象不会暂停在官方脚本中有解释 Time.timeScale = 0;Time.timeScale 的确是能暂停一些东西。但是如果在update函数中持续改变一个物体的位置,这种位置改变貌似是不会受到暂停影响的。
transform.position = transform.position+transform.TransformDirection(Vector3(0,0,throwForce));
Time.timeScale = 0的时候这个东西仍然在动~~~~~
Time.timeScale

Time.timeScale

The scale at which the time is passing. This can be used for slow motion effects.

When timeScale is 1.0 the time is passing as fast as realtime. When timeScale is 0.5 the time is passing 2x slower than realtime.

When timeScale is set to zero the game is basically paused if all your functions are frame rate independent.

Except for realtimeSinceStartup, timeScale affects all the time and delta time measuring variables of the Time class.

If you lower timeScale it is recommended to also lower Time.fixedDeltaTime by the same amount.

FixedUpdate functions will not be called when timeScale is set to zero.
---------------------------------------------------------------------

可以试试FixedUpdate()

你们说的那种情况我暂时还没遇到过。
----------------------------------------------------------------------

在Unity Answer上看到有人用这样的方法:

When the game needs to pause, call the OnPauseGame function on all objects using something like this:

Object[] objects = FindObjectsOfType (typeof(GameObject));
foreach (GameObject go in objects) {
go.SendMessage ("OnPauseGame", SendMessageOptions.DontRequireReceiver);
}

And to resume call OnResumeGame on all objects.
A basic script with movement in the Update() could have something like this:
protected bool paused;

void OnPauseGame ()
{
paused = true;
}

void OnResumeGame ()
{
paused = false;
}

void Update ()
{
if (!paused) {
// do movement
}
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com