繁体   English   中英

如果我在学分场景之前进入游戏场景,使面板向上滚动的Unity 2018脚本将无法工作

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM