Unity3D v5.4 - GUILayout does not exist
本文关键字:does not exist GUILayout v5 Unity3D | 更新日期: 2023-09-27 18:03:30
我正在尝试制作游戏菜单。为此,我需要GUIlayout
和它的方法。然而,看起来Unity
找不到GUIlayout
对象,显示此错误:
我代码:Assets/scripts/GameManager.cs(38,25):错误CS0103:名称"GUIlayout"在当前上下文中不存在
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大写。
。使用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");
}
}
最后,你不应该使用这个。你应该使用新的Unity UI。这里有一个教程