我的场景中有两个脚本。第一个是慢动作脚本。第二个是暂停菜单。在我的暂停菜单脚本中,我有Time.timescale = 0或1,具体取决于它是否暂停。
在我的慢动作脚本中,我还使用Time.timescale来创建"慢动作"影响。出于某种原因,如果启用了暂停菜单脚本,我将无法使用慢动作。如果它被禁用,它就可以正常工作。所以我得出结论,问题是Time.timescale(我甚至测试过它)。
这是我的暂停菜单脚本:
public bool isPaused;
public GameObject canvasPause;
MouseLook fpCamMouseLook;
MouseOrbitImproved tpCamOrbitLook;
// Use this for initialization
void Start () {
fpCamMouseLook = GameObject.Find ("Main Camera").GetComponent<MouseLook> ();
tpCamOrbitLook = GameObject.Find ("ThirdPersonCamera").GetComponent<MouseOrbitImproved> ();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Escape)) {
// switch for pause boolean
isPaused = !isPaused;
}
if (isPaused == true) {
AudioListener.volume = 0f;
canvasPause.SetActive (true);
Time.timeScale = 0;
fpCamMouseLook.enabled = false;
tpCamOrbitLook.enabled = false;
} else {
AudioListener.volume = 1f;
canvasPause.SetActive (false);
Time.timeScale = 1;
fpCamMouseLook.enabled = true;
tpCamOrbitLook.enabled = true;
}
}
// back to menu button
public void goBackToMenu(){
Application.LoadLevel ("Menu");
}
public void quitToDesktop(){
Application.Quit ();
}
public void unPause(){
canvasPause.SetActive (false);
}
这是我的慢动作剧本:
float currentAmount = 0f;
float maxAmount = 5f;
public bool isSlowMo;
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.Tab)){
isSlowMo = !isSlowMo;
}
if (isSlowMo == true) {
if (Time.timeScale == 1.0f)
Time.timeScale = 0.3f;
} else {
Time.timeScale = 1.0f;
Time.fixedDeltaTime = 0.02f * Time.timeScale;
}
if(Time.timeScale == 0.03f){
currentAmount += Time.deltaTime;
}
if(currentAmount > maxAmount){
currentAmount = 0f;
Time.timeScale = 1.0f;
}
}
请帮帮忙?
答案 0 :(得分:0)
我为自己找到了一个更简单的解决方案。我刚决定暂停播放器的输入而不是暂停时间。它对我来说很好。谢谢!