Unity3D v5.4 - GUILayout 不存在
Unity3D v5.4 - GUILayout does not exist
我正在尝试制作游戏菜单。为此,我需要 GUIlayout
及其方法。但是,看起来 Unity
找不到 GUIlayout
对象,显示此错误:
Assets/scripts/GameManager.cs(38,25): error CS0103: The name `GUIlayout' does not exist in the current context
我的代码:
using UnityEngine;
using UnityEditor;
using System.Collections;
public class GameManager : MonoBehaviour {
public bool isMenuActive{get;set;}
void Awake () {
isMenuActive = true;
}
void OnGUI(){
const int Width = 300;
const int Height = 200;
if (isMenuActive){
Rect windowRect = new Rect((Screen.width - Width) / 2 ,(Screen.height - Height) / 2, Width , Height);
GUIlayout.window(0,windowRect,MainMenu,"Main menu");
}
}
private void MainMenu(){
// Debug.Log("menu is displayed");
}
}
有什么想法吗?
问题出在代码行:
GUILayout.Window(0, windowRect, MainMenu, "Main menu");
1。是 GUILayout
而不是 GUIlayout
。 'L' 是大写的。
2。使用的GUILayout
静态函数是Window
不是window
。来自问题 #1 的相同大写问题。
3.Window
函数的第三个参数需要传入一个int参数的函数。您必须使用 int
.
参数化 MainMenu
函数
public class GameManager : MonoBehaviour
{
public bool isMenuActive { get; set; }
void Awake()
{
isMenuActive = true;
}
void OnGUI()
{
const int Width = 300;
const int Height = 200;
if (isMenuActive)
{
Rect windowRect = new Rect((Screen.width - Width) / 2, (Screen.height - Height) / 2, Width, Height);
GUILayout.Window(0, windowRect, MainMenu, "Main menu");
}
}
private void MainMenu(int windowID)
{
// Debug.Log("menu is displayed");
}
}
最后,您不应该使用 this. You should be using the new Unity UI. Here 的教程。
我正在尝试制作游戏菜单。为此,我需要 GUIlayout
及其方法。但是,看起来 Unity
找不到 GUIlayout
对象,显示此错误:
Assets/scripts/GameManager.cs(38,25): error CS0103: The name `GUIlayout' does not exist in the current context
我的代码:
using UnityEngine;
using UnityEditor;
using System.Collections;
public class GameManager : MonoBehaviour {
public bool isMenuActive{get;set;}
void Awake () {
isMenuActive = true;
}
void OnGUI(){
const int Width = 300;
const int Height = 200;
if (isMenuActive){
Rect windowRect = new Rect((Screen.width - Width) / 2 ,(Screen.height - Height) / 2, Width , Height);
GUIlayout.window(0,windowRect,MainMenu,"Main menu");
}
}
private void MainMenu(){
// Debug.Log("menu is displayed");
}
}
有什么想法吗?
问题出在代码行:
GUILayout.Window(0, windowRect, MainMenu, "Main menu");
1。是 GUILayout
而不是 GUIlayout
。 'L' 是大写的。
2。使用的GUILayout
静态函数是Window
不是window
。来自问题 #1 的相同大写问题。
3.Window
函数的第三个参数需要传入一个int参数的函数。您必须使用 int
.
MainMenu
函数
public class GameManager : MonoBehaviour
{
public bool isMenuActive { get; set; }
void Awake()
{
isMenuActive = true;
}
void OnGUI()
{
const int Width = 300;
const int Height = 200;
if (isMenuActive)
{
Rect windowRect = new Rect((Screen.width - Width) / 2, (Screen.height - Height) / 2, Width, Height);
GUILayout.Window(0, windowRect, MainMenu, "Main menu");
}
}
private void MainMenu(int windowID)
{
// Debug.Log("menu is displayed");
}
}
最后,您不应该使用 this. You should be using the new Unity UI. Here 的教程。