Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.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
Unity3d 如何在NGUI中获取相机宽度和按钮宽度_Unity3d_Ngui - Fatal编程技术网

Unity3d 如何在NGUI中获取相机宽度和按钮宽度

Unity3d 如何在NGUI中获取相机宽度和按钮宽度,unity3d,ngui,Unity3d,Ngui,我正在尝试访问NGUI 2D UI摄像头的宽度和高度,还尝试访问使用NGUI创建的按钮的宽度和高度。我刚刚想出来 UIPanel uiPanel = GameObject.Find ("UI Root").GetComponent<UIPanel>(); print(uiPanel.width"); print("uiPanel.height"); UIPanel UIPanel=GameObject.Find(“UI根”).GetComponent(); 打印(uiPanel.

我正在尝试访问NGUI 2D UI摄像头的宽度和高度,还尝试访问使用NGUI创建的按钮的宽度和高度。

我刚刚想出来

UIPanel uiPanel = GameObject.Find ("UI Root").GetComponent<UIPanel>();

print(uiPanel.width");
print("uiPanel.height");
UIPanel UIPanel=GameObject.Find(“UI根”).GetComponent();
打印(uiPanel.width);
打印(“uiPanel.height”);

另一种方法可以是:

var uiPanel = NGUITools.GetRoot(gameObject).GetComponent<UIPanel>();
print(uiPanel.width");
print("uiPanel.height");
var uiPanel=NGUITools.GetRoot(gameObject.GetComponent();
打印(uiPanel.width);
打印(“uiPanel.height”);

在找到之前,避免在所有场景层次中查找对象。此外,如果您使用多个UICamera,因此使用多个UIRoots,请确保使用正确的UICamera。

什么版本的NGUI?我使用的是NGUI v3.5.4r2版本。