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

时间:2014-05-08 08:48:23

标签: unity3d ngui

我尝试访问NGUI 2D UI相机的宽度和高度,并尝试使用NGUI访问按钮创建的宽度和高度。

2 个答案:

答案 0 :(得分:0)

我只是想出来

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

print(uiPanel.width");
print("uiPanel.height");

答案 1 :(得分:0)

另一种方法可能是:

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

并且您无法通过所有场景层次结构查找对象,直到找到它为止。此外,如果您使用多个UICameras并因此使用多个UIRoot,请确保获得正确的UICame。

相关问题