如何使用退出键在主菜单视图模式和播放视图模式之间切换并移动相机?
How can i use the escape key to switch between main menu view mode and playing view mode and move the camera?
我想做的是,当我在游戏中的任何时间和地点单击一次退出键时,它会将相机移动到主菜单视图,这意味着非常靠近玩家,然后一切都会闲置而不是冻结.并且将显示主菜单。再次单击退出键会将相机移回玩家身后,我认为这是播放视图时的正确位置。不确定,但我认为在播放视图模式时,相机应该位于播放器的后面和上方。
现在我所做的是 运行 游戏在主菜单视图中(我还没有创建主菜单)。我也这样做了,当我单击转义键时,它冻结了游戏,然后再次单击使用 Time.timeScale 并在 0 和 1 之间切换来继续游戏。
但是Time.timeScale 冻结我想在主菜单中闲置的游戏。
而且我不确定每次在视图模式之间切换时如何使相机移动平稳。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainMenu : MonoBehaviour {
int count = 0;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (count == 0)
{
Time.timeScale = 0;
count = 1;
}
else
{
Time.timeScale = 1;
count = 0;
}
// to make here a switching mode between
//playing screen and pause/main menu screen.
}
}
}
主菜单视图的屏幕截图
我会使用 Animator
组件来移动您的 Camera
。在该 Animator 中将更新模式设置为 "Unscaled Time"。这样,当您的时间刻度为 0 时,它会继续工作。
我想做的是,当我在游戏中的任何时间和地点单击一次退出键时,它会将相机移动到主菜单视图,这意味着非常靠近玩家,然后一切都会闲置而不是冻结.并且将显示主菜单。再次单击退出键会将相机移回玩家身后,我认为这是播放视图时的正确位置。不确定,但我认为在播放视图模式时,相机应该位于播放器的后面和上方。
现在我所做的是 运行 游戏在主菜单视图中(我还没有创建主菜单)。我也这样做了,当我单击转义键时,它冻结了游戏,然后再次单击使用 Time.timeScale 并在 0 和 1 之间切换来继续游戏。
但是Time.timeScale 冻结我想在主菜单中闲置的游戏。 而且我不确定每次在视图模式之间切换时如何使相机移动平稳。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainMenu : MonoBehaviour {
int count = 0;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (count == 0)
{
Time.timeScale = 0;
count = 1;
}
else
{
Time.timeScale = 1;
count = 0;
}
// to make here a switching mode between
//playing screen and pause/main menu screen.
}
}
}
主菜单视图的屏幕截图
我会使用 Animator
组件来移动您的 Camera
。在该 Animator 中将更新模式设置为 "Unscaled Time"。这样,当您的时间刻度为 0 时,它会继续工作。