如果我在积分场景之前进入游戏场景,使面板向上滚动的 Unity 2018 脚本将不起作用
Unity 2018 script to make panel scroll up wont work if I go to the game scene before the credits scene
我正在 Unity3D 中开发游戏(我还会制作什么),到目前为止我有主菜单场景、游戏场景和制作人员场景。
我制作了一个脚本(如下所示),如果我从主菜单 select 演职员表场景,它将使包含名称的面板向上滚动,效果很好。但这就是问题所在。如果我先进入游戏然后返回主菜单 rand select 积分什么也不会发生。有什么想法吗?
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);
}
}
您将翻译移到了 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
因为它已被弃用,将来会被删除。
我正在 Unity3D 中开发游戏(我还会制作什么),到目前为止我有主菜单场景、游戏场景和制作人员场景。
我制作了一个脚本(如下所示),如果我从主菜单 select 演职员表场景,它将使包含名称的面板向上滚动,效果很好。但这就是问题所在。如果我先进入游戏然后返回主菜单 rand select 积分什么也不会发生。有什么想法吗?
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);
}
}
您将翻译移到了 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
因为它已被弃用,将来会被删除。