- Home /
This post has been wikified, any user with enough reputation can edit it.
How can I access the childs of a sprite on multiple mode?
What I'm doing is trying to access the array of sprites under the "root texture" using an editor script
//EDITOR BUTTON TO INSTANTIATE SEVERAL SPRITES ON SCREEN AT ONCE
[MenuItem ("GameObject/Create Other/InstSprites")]
static void InstSprites()
{
//IF THERE IS SOMETHING SELECTED ON INSPECTOR/PROJECT
if (Selection.activeObject != null)
{
Sprite[] textures = //WHAT SHOULD I WRITE HERE TO IMPORT THE ARRAY OF SPRITES?
//THIS SHOULD BE AN OPTION, BUT IT DOENS'T WORK AS I EXPECTED...
// UnityEngine.Object[] allSprites = Selection.objects;
string[] names = new string[textures.Length];
for(int ii=0; ii< names.Length; ii++) {
names[ii] = textures[ii].name;
Debug.Log(names[ii]);
GameObject ssprite = new GameObject();
ssprite.name = names[ii];
ssprite.AddComponent<SpriteRenderer>();
ssprite.GetComponent<SpriteRenderer>().sprite = Sprite.Create(textures[ii].texture, textures[ii].textureRect, Vector2.zero , 100f);
}
}
}
That's it. Any Insights?
Thank you.
Comment