Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: slayerlp on February 10, 2013, 05:19:24 PM

Title: Destroying UISprites in game via code
Post by: slayerlp on February 10, 2013, 05:19:24 PM
Hi, i have nested into the panel a gameObject with UISprites as childrens.
I want to destroy the Sprites, but the only way i found is:

  1. public GameObject LivesInGame;
  2.  
  3. ...
  4.  
  5. LivesInGame.transform.GetChild(lives).GetComponent<UISprite>().enabled=false;

this works good but,
is this right to use??

Title: Re: Destroying UISprites in game via code
Post by: ArenMook on February 10, 2013, 11:08:12 PM
1. You're disabling the sprite component, not destroying it.
2. Create a script that has public UISprite variables, attach this script to our LivesInGame game object, and drag & drop the fields in the inspector. Way cleaner than GetChild/GetComponent.