基于Unity3D的2d拾宝游戏(八)游戏界面显示screenSet类

发表于2017-11-30
评论0 890浏览

UI控制类介绍完了之后,接下来就要开始给大家介绍游戏界面显示screenSet类的内容,一起来看看吧。


游戏界面显示screenSet类(即游戏时控制全屏退出等操作):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class screenSet : MonoBehaviour {
    void Awake()
    {
        //获取设置当前屏幕分辩率  
        Resolution[] resolutions = Screen.resolutions;
        //设置当前分辨率  
        Screen.SetResolution(resolutions[resolutions.Length - 1].width, resolutions[resolutions.Length - 1].height, true);
        Screen.fullScreen = false;  //设置成全屏,  
    }
    // Update is called once per frame  
    void Update()
    {
        //  按ESC退出全屏  
        if (Input.GetKey(KeyCode.Escape))
        {
            Screen.fullScreen = false;  //退出全屏           
        }
    }
}


游戏场景控制SenceControler类(包括关卡转场、返回界面等控制):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SenceControler : MonoBehaviour {
    public Texture2D winTexture;
    private float myTime;
    private bool isNextSence;
    // Use this for initialization
    void Start () {
        myTime = 0;
        isNextSence = false;
    }   
    // Update is called once per frame
    void Update () {
        myTime += Time.deltaTime;
        if (myTime >= 5)
        {
            isNextSence = true;
        }
        if (Input.GetButtonDown("Jump") && isNextSence)
        {
            isNextSence = false;
            int index = Application.loadedLevel;//第一个关卡为0,第二个为1,依次推
            if (index <= 2)
                Application.LoadLevel(index + 1);
            if (index == 3)
                Application.LoadLevel(4);
        }
    }
    void OnGUI()
    {
        if (isNextSence)
        {
            GUI.DrawTexture(new Rect(Screen.width / 2 - 179, Screen.height / 2 - 90, 358, 180), winTexture,ScaleMode.ScaleToFit,true,0);//根据所需素材调节显示大小
        }
    }
}

完。

如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引

0个评论