Author Topic: Destroying UISprites in game via code  (Read 1989 times)

slayerlp

  • Guest
Destroying UISprites in game via code
« 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??


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Destroying UISprites in game via code
« Reply #1 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.