Last active
December 29, 2015 21:09
-
-
Save Buravo46/7728422 to your computer and use it in GitHub Desktop.
【Unity】シーンを切り替えるためのGUIを生成するスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class SceceChangeGUIScript : MonoBehaviour { | |
// GUIに使うSkin | |
public GUISkin skin; | |
// 切り替え先のScene名 | |
public string sceneName = ""; | |
// ボタンの名前 | |
public string buttonLabel = ""; | |
// ボタンの幅 | |
public float buttonWidth = 0; | |
// ボタンの高さ | |
public float buttonHeight = 0; | |
// 座標をズラす値X | |
public float offsetX = 0; | |
// 座標をズラす値Y | |
public float offsetY = 0; | |
// ボタンの座標X | |
private float buttonPositionX = 0; | |
// ボタンの座標Y | |
private float buttonPositionY = 0; | |
void start (){ | |
// ボタンの座標X | |
buttonPositionX = Screen.width/2 - buttonWidth/2 - offsetX; | |
// ボタンの座標Y | |
buttonPositionY = Screen.height/2 - buttonHeight/2 - offsetY; | |
} | |
void OnGUI () { | |
// Skin代入 | |
GUI.skin=skin; | |
// GUI生成 | |
if(GUI.Button(new Rect(buttonPositionX,buttonPositionY, buttonWidth, buttonHeight), buttonLabel, "button")){ | |
Application.LoadLevel(sceneName); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma strict | |
// GUIに使うSkin | |
var skin : GUISkin; | |
// 切り替え先のScene名 | |
var sceneName:String = ""; | |
// ボタンの名前 | |
var buttonLabel:String = ""; | |
// ボタンの幅 | |
var buttonWidth:float = 0; | |
// ボタンの高さ | |
var buttonHeight:float = 0; | |
// 座標をズラす値X | |
var offsetX:float = 0; | |
// 座標をズラす値Y | |
var offsetY:float = 0; | |
// ボタンの座標X | |
private var buttonPositionX:float = 0; | |
// ボタンの座標Y | |
private var buttonPositionY:float = 0; | |
function Start () { | |
buttonPositionX = Screen.width/2 - buttonWidth/2 - offsetX; | |
buttonPositionY = Screen.height/2 - buttonHeight/2 - offsetY; | |
} | |
function Update () { | |
} | |
function OnGUI(){ | |
// Skin代入 | |
GUI.skin=skin; | |
// GUI生成 | |
if(GUI.Button(Rect(buttonPositionX,buttonPositionY, buttonWidth, buttonHeight), buttonLabel, "button")){ | |
Application.LoadLevel(sceneName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment