Author Topic: NGUITools.AddWidgetCollider doesn't work!  (Read 4162 times)

xiaoniaojjj

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
NGUITools.AddWidgetCollider doesn't work!
« 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.         }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUITools.AddWidgetCollider doesn't work!
« Reply #1 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.