Unity入门操作_Application类与切换场景 _010

生成场景并转换!
Unity5.3
UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class ApplicationnDemo : MonoBehaviour {

// Use this for initialization
void Start () {
    Debug.Log(SceneManager.GetActiveScene().buildIndex);
    Debug.Log(SceneManager.sceneCount);
}
// Update is called once per frame
void Update () {  
}
void OnGUI()
{
    if (GUI.Button(new Rect(0,0,60,40),"截图"))
    {
        Application.CaptureScreenshot("./Picture/11");
        Debug.Log("截图成功");
        Application.CaptureScreenshot(Application.dataPath + "/Picture/123.png");//得到相对路径 

    }
    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();
}

}
5.2
using UnityEngine;
using System.Collections;

public class ApplicationDemo : MonoBehaviour {

// Use this for initialization
void Start () {
    Debug.Log(Application.loadedLevel +" 场景测试");
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
    if (GUI.Button(new Rect(0,0,60,40),"截图"))
    {
        Application.CaptureScreenshot(@"/Pictures/YY.png");
        Debug.Log("截图成功");            Application.CaptureScreenshot(Application.dataPath + "/Pictures/YY.png");
    }
    //5.3中使用SceneManager.sceneCount 替代 Application.levelCount
    if (Application.loadedLevel != Application.levelCount-1)
    {

        if (GUI.Button(new Rect(0, 45, 60, 40), "下一个关卡"))
        {
            //5.3  使用下面的方法  替代5.2中的
            //SceneManager.LoadScene(0);Application.LoadLevel(0);

            Application.LoadLevel(Application.loadedLevel + 1);
            //gamemanager是脚本绑定到的空物体的名字
            GameObject gamemanager = GameObject.Find("GameManager");
            DontDestroyOnLoad(gamemanager);
        }
    }
    if (Application.loadedLevel!=0)
    {
        if (GUI.Button(new Rect(0, 90, 60, 40), "上一个关卡"))
        {
            Application.LoadLevel(Application.loadedLevel - 1);
        }
    }
}

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

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值