Hi,
I'm trying to find the root GameObject if a child object that has a UIButton component. When the child object is clicked, I would like to record the root GameObject. I am using the following which brings up an error;
public GameObject RootGameObject;
void OnClick()
{
UIButton btn = UIButton.current;
RootGameObject = btn.transform.root.gameObject;
// Debug.Log(UIButton.current.name);
}
The error is:
NullReferenceException: Object reference not set to an instance of an object
KeepTrackOfOpenWindow.OnClick () (at Assets/Khoda/Scripts/Q&A/KeepTrackOfOpenWindow.cs:12)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
UICamera:Notify(GameObject, String, Object) (at Assets/NGUI/Scripts/UI/UICamera.cs:1065)
UICamera:ProcessTouch(Boolean, Boolean) (at Assets/NGUI/Scripts/UI/UICamera.cs:1808)
UICamera:ProcessMouse() (at Assets/NGUI/Scripts/UI/UICamera.cs:1402)
UICamera:ProcessTouches() (at Assets/NGUI/Scripts/UI/UICamera.cs:1474)
UICamera:Update() (at Assets/NGUI/Scripts/UI/UICamera.cs:1221)
Any help wuld be great - Thanks