1. 程式人生 > >基於Unity3D的2d拾寶遊戲(八)

基於Unity3D的2d拾寶遊戲(八)

遊戲介面顯示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);//根據所需素材調節顯示大小 } } }

完。