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
}
}
本文介绍了一种在Unity中实现游戏暂停与恢复的方法。通过使用C#脚本,发送消息给所有游戏对象来实现全局性的暂停效果。关键在于利用GameObject的SendMessage方法,并通过Update函数内的条件判断来控制游戏对象的行为。
828

被折叠的 条评论
为什么被折叠?



