Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: xiaoniaojjj on October 31, 2012, 04:34:56 AM

Title: NGUITools.AddWidgetCollider doesn't work!
Post by: xiaoniaojjj on October 31, 2012, 04:34:56 AM
It's my code, after NGUITools.AddWidgetCollider(uLabel.gameObject); the gameObject didn't add the BoxCollider ,
Who can tell me why?
  1. void OnClick()
  2.         {              
  3.                 string msg = uInputField.text;
  4.                 GameObject goLabel = GameObject.Instantiate(uLabelMsgTemp) as GameObject;
  5.                 UILabel uLabel = goLabel.GetComponentInChildren<UILabel>();
  6.                 uLabel.text = msg;
  7.                 Vector3 scale = goLabel.transform.localScale;
  8.                 NGUITools.AddChild(uTextList.gameObject,goLabel);
  9.                 goLabel.transform.localScale = scale;
  10.                 NGUITools.AddWidgetCollider(uLabel.gameObject);
  11.                 uTextList.repositionNow = true;
  12.         }
Title: Re: NGUITools.AddWidgetCollider doesn't work!
Post by: ArenMook on October 31, 2012, 08:52:19 AM
You create a game object -- and you never parent it. The resulting widgets is not a part of the UI.

Use NGUITools.AddChild instead.

Also look into NGUITools.AddWidget.