【发布时间】:2018-04-23 04:25:25
【问题描述】:
我的场景中有两个脚本。第一个是慢动作脚本。第二个是暂停菜单。在我的暂停菜单脚本中,我的 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;
}
}
请帮忙?
【问题讨论】:
-
Time.timeScale 是全局的。两个脚本都在每帧更改字段。