qq_39930305
qq_39930305
采纳率0%
2017-08-25 06:55 阅读 3.3k

unity3d / 按钮 /切换

求问unity3d中如何:实现点击添加的按钮,使一个场景跳转到另一个场景?谢谢啦!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • qq_39710961 wy小骑士 2017-08-25 09:56

    Unity5.3
    UnityEngine;
    using System.Collections;
    using UnityEngine.SceneManagement;
    public class ApplicationnDemo : MonoBehaviour {

    // Use this for initialization
    void Start () {
    }
    // Update is called once per frame
    void Update () {

    }
    void OnGUI()
    {

    Debug.Log(SceneManager.GetActiveScene().buildIndex +"当前关卡");
    Debug.Log(SceneManager.sceneCountInBuildSettings +"游戏加载关卡总数");
    //表示游戏关卡总数减一得到最大索引
    if (SceneManager.GetActiveScene().buildIndex != SceneManager.sceneCountInBuildSettings -1)
    {
        if (GUI.Button(new Rect(0, 45, 60, 40), "下一关"))
        {
            GameObject gamemanger = GameObject.Find("GameObject1");
            DontDestroyOnLoad(gamemanger);
            //获取当前活跃的场景加1
            int index = SceneManager.GetActiveScene().buildIndex + 1;
            SceneManager.LoadScene(index);
        }
    }
    if (SceneManager.GetActiveScene().buildIndex != 0)
    {
        if (GUI.Button(new Rect(0, 90, 60, 40), "上一关"))
        {       SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
        }
    }
    

    }
    void OnApplicationQuit()
    {
    Application.Quit();
    }

    }

    点赞 1 评论 复制链接分享

相关推荐