[英]Unity 2018 script to make panel scroll up wont work if I go to the game scene before the credits scene
我正在使用Unity3D開發一款游戲(我還會做些什么),到目前為止,我擁有主菜單場景,游戲場景和Credits場景。
我編寫了一個腳本(如下所示),該腳本將使包含名稱的面板向上滾動,如果我從主菜單中選擇了信用場景,該腳本也可以正常工作。 但這是問題所在。 如果我先去玩游戲,然后再回到主菜單rand select credits,則什么也沒有發生。 有任何想法嗎?
using UnityEngine;
using System.Collections;
public class ScrollCredits : MonoBehaviour
{
public GameObject Canvas;
public int speed = 1;
public string level;
private void Start()
{
Canvas.transform.Translate(Vector3.up * Time.deltaTime * speed);
StartCoroutine(waitFor());
}
private void Update()
{
}
IEnumerator waitFor()
{
yield return new WaitForSeconds (69);
Application.LoadLevel(level);
}
}
您將Translate移到Start()
,它將無法正常工作。 只有StartCoroutine
應該在Start()
,如下所示:
public GameObject canvas;
public float speed = 0.1f;
public string sceneName;
public float timer;
private void Start()
{
StartCoroutine(WaitFor());
}
private void Update()
{
canvas.transform.Translate(Vector3.right * Time.deltaTime * speed);
}
IEnumerator WaitFor()
{
yield return new WaitForSeconds (timer);
SceneManager.LoadScene(sceneName);
}
注意:我已將LoadLevel
更改為SceneManager.LoadScene
因為它已被棄用,並且將來會被刪除。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.