這是一個用下拉式選單選擇場景,當遊戲運行後,玩家點擊物體(按鈕)就會依造選擇的場景地進入指定場景
還有如果按下 Esc 鍵,或手機的 Back 鍵也會觸發進入到指定的場景中,
這可以使用 UseBack 來控制是否要啟用這個功能
可以設定啟用 Click (滑鼠點擊),或 Back (按 Esc 鍵、按手機的 Back 鍵)
下拉選單:選擇要進入的場景
using UnityEngine;
using System.Collections;
public class ToScene : MonoBehaviour {
public enum Scene
{
FirstPage, // Scene 場景名稱 (一定與實際場景名稱相符)
MainPage, // 以下為每個場景的名稱,之後記得到 Unity 介面去選擇要進入的場景
ChooseLocalPage,
PlayModePage,
UploadPage
};
public Scene SceneName;
public bool useClick = true;
public bool useBack;
void OnClick () {
if(useClick){
Application.LoadLevel(SceneName.ToString());
}
}
void Update () {
if(useBack){
if(Input.GetKeyDown(KeyCode.Escape)){
Application.LoadLevel(SceneName.ToString());
}
}
}
}
場景分類版本:
public enum CommunityScene{
Null,
AddFriend,
Message,
Friend,
Talk,
GroupMessage
}
public enum PasswordScene{
Null,
InputPassword,
SetPassword,
SetPassword2
}
public enum OtherScene{
Null,
Achievements,
Backup,
Error,
FoodCamera,
FoodCamera2,
FoodChoose,
FoodHistory,
FoodInformation,
Init,
MainMenu,
ReadBackup,
SetBirthday,
Setting,
SetWeight,
Sports,
Sports2,
User,
User2,
User3,
UserCamera,
Waiter,
Waiter2,
WeightMeasurements,
WeightMeasurements2
};
public CommunityScene communityScene;
public PasswordScene passwordScene;
public OtherScene otherScene;
public bool useClick = true;
public bool useBack;
void OnClick () {
if(useClick){
string community = communityScene.ToString();
string password = passwordScene.ToString();
string other = otherScene.ToString();
string nul = "Null";
if(community != nul){
Application.LoadLevel(community);
}else if(password != nul){
Application.LoadLevel(password);
}else if(other != nul){
Application.LoadLevel(other);
}
}
}
void Update () {
if(useBack){
if(Input.GetKeyDown(KeyCode.Escape)){
Application.LoadLevel(otherScene.ToString());
}
}
}