Author Topic: NGUI Sprire not visible in 3d when added by code  (Read 2450 times)

alexKhvorov

  • Guest
NGUI Sprire not visible in 3d when added by code
« on: September 25, 2013, 11:29:55 AM »
As above

When i add them by hand its nice two-sided GO with sprites, but when i do this by code
  1.             GameObject squadUnit = new GameObject("squadUnit"+i);
  2.                         UISprite uiSpr = squadUnit.AddComponent<UISprite>();
  3.                         uiSpr.atlas = atlas;
  4.                         uiSpr.spriteName = "frame2";
  5.                         uiSpr.panel = uiPanel;
  6.                         squadUnit.transform.parent = panel.transform;
  7.                         UISpriteAnimation uiSprAnim = squadUnit.AddComponent<UISpriteAnimation>();
  8.                         uiSprAnim.framesPerSecond = 8;
  9.                         uiSprAnim.namePrefix = "frame";
  10.  
I see a rectangles but animation frames not visible
How to add them properly?

« Last Edit: September 25, 2013, 11:38:09 AM by alexKhvorov »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Sprire not visible in 3d when added by code
« Reply #1 on: September 25, 2013, 07:26:04 PM »
You need to use NGUITools.AddChild<UISprite>(parent), not new GameObject/AddComponent. You never set the layer, which is your problem.