Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Unity3D保存移动GUI按钮_Android_User Interface_Mobile_Unity3d_Save - Fatal编程技术网

Android Unity3D保存移动GUI按钮

Android Unity3D保存移动GUI按钮,android,user-interface,mobile,unity3d,save,Android,User Interface,Mobile,Unity3d,Save,通过按p键,我有了桌面的代码,但我无法获得移动gui按钮。我一直在使用Corona SDK,我是Unity3D的新手。请帮我把“按p”变成一个GUI按钮,上面写着“保存”。提前谢谢 import System.Collections.Generic; var paused : boolean = false; var pausedGUI : GUITexture; var gameName : String = "Your Game"; var myList = new List.&l

通过按p键,我有了桌面的代码,但我无法获得移动gui按钮。我一直在使用Corona SDK,我是Unity3D的新手。请帮我把“按p”变成一个GUI按钮,上面写着“保存”。提前谢谢

import System.Collections.Generic;

var paused : boolean = false; 
var pausedGUI : GUITexture;  
var gameName : String = "Your Game";

var myList = new List.<Transform>();

function Start()
{
    if(pausedGUI)
        pausedGUI.enabled = false;
}

function Update () 
{ 
    if(Input.GetKeyUp(KeyCode.P))
    { 
       paused = !paused;

        if(paused == true){
            Time.timeScale = 0.0;
            if(pausedGUI) pausedGUI.enabled = true;
        } else {
            Time.timeScale = 1.0;
            if(pausedGUI) pausedGUI.enabled = false;
        }
   }
}

function OnGUI() {
    if(!paused)
    {
       GUILayout.BeginArea(Rect(200,10,400,20));
       GUILayout.BeginVertical();
       GUILayout.BeginHorizontal();
       GUILayout.FlexibleSpace();
       GUILayout.Label("Press P to Pause");
       GUILayout.FlexibleSpace();
       GUILayout.EndHorizontal();
       GUILayout.EndVertical();
       GUILayout.EndArea();
       return;
    }

    var box : GUIStyle = "box";   
    GUILayout.BeginArea(Rect( Screen.width/2 - 200,Screen.height/2 - 300, 400, 600), box);

    GUILayout.BeginVertical(); 
    GUILayout.FlexibleSpace();
    if(GUILayout.Button("Save Game"))
    {
       LevelSerializer.SaveGame(gameName);
    }
    GUILayout.Space(60);
    for(var sg in LevelSerializer.SavedGames[LevelSerializer.PlayerName]) { 
       if(GUILayout.Button(sg.Caption)) { 
         LevelSerializer.LoadNow(sg.Data);
         Time.timeScale = 1;
         } 
    } 
    GUILayout.FlexibleSpace();
    GUILayout.EndVertical();
    GUILayout.EndArea();


}
导入System.Collections.Generic;
var暂停:boolean=false;
var pausedGUI:吉他织物;
var gameName:String=“您的游戏”;
var myList=新列表。();
函数Start()
{
如果(暂停用户界面)
pausedGUI.enabled=false;
}
函数更新()
{ 
if(Input.GetKeyUp(KeyCode.P))
{ 
暂停=!暂停;
如果(暂停==真){
Time.timeScale=0.0;
如果(pausedGUI)pausedGUI.enabled=true;
}否则{
Time.timeScale=1.0;
如果(pausedGUI)pausedGUI.enabled=false;
}
}
}
函数OnGUI(){
如果(!暂停)
{
BeginArea(Rect(200,10400,20));
GUILayout.beginstical();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label(“按P暂停”);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.EndVertical();
GUILayout.EndArea();
返回;
}
变量框:GUIStyle=“box”;
GUILayout.BeginArea(Rect(Screen.width/2-200,Screen.height/2-300400600),方框);
GUILayout.beginstical();
GUILayout.FlexibleSpace();
if(GUILayout.按钮(“保存游戏”))
{
LevelSerializer.SaveGame(gameName);
}
空间(60);
对于(LevelSerializer.SavedGames[LevelSerializer.PlayerName]中的var sg){
if(GUILayout.Button(sg.Caption)){
LevelSerializer.LoadNow(sg.Data);
Time.timeScale=1;
} 
} 
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
GUILayout.EndArea();
}

在此处查看我的游戏:

您只需在OnGUI调用的开始处放置一个按钮,即可切换暂停状态

function OnGUI(){
  if(!paused){
    if(GUILayout.Button("Pause Game"))
    {
      paused = true;
    }
  }else{
    if(GUILayout.Button("Resume Game"))
    {
      paused = false;
    }
  }

...
抱歉,如果语法有点错误,我通常会这样做这是C:)

您将需要进行格式化以将按钮放置在正确的位置,但这取决于您的游戏布局

希望这有帮助