Hi guys,
I want to create empty GameObject, add a SpriteRenderer component into it and then be able to set the Sprite property of the SpriteRenderer component. I have the name of the Sprite that I want to create (the name which is display in the Assets folder) - is there a way to create/instantiate a Sprite with that information ?
Thank you.
I think you shall create a prefab as per your requirement and then Instantiate that prefab whenever you want. Alternatively if you want to completely make it dynamic then since you have the name of the sprite, you can load it from Resources.Load method and assign it to the sprite property of the SpriteRenderer.
Does Resources.Load allow to load texture which is actually a subTexture from a Sprite packed as Multiple ?
You can also make a public Sprite variable in your script and assign the sprite (a subTexture from a Sprite packed as Multiple) to it. Or even a list of Sprite’s.
The thing is that I have tons of Sprite (sub-texture) - it would take me so long to drag-&-drop each one into a script.
Is there a way to directly use the Sprite which is “multipack” into a script ? What type of object it is ?
Hmm, you can drag all of them and drop on a list, but if you have a lot of sprites maybe Resource.Load is the way to go.
Yes.
http://stackoverflow.com/questions/24977986/load-sprite-from-asset-sprites
That’s impossible as once you try to select several files, the IDE loses focus on object and you cannot drag and drop. Resources does not work either… just for small projects. Steaming resources also s@ck because there are some universal cases (thanks to google) when android fails and you will end up with 2% crashes which you are unable to resolve… So the only way to do it, just add all sprites via properties but doing that for hundreds of sprites is wrong path for sure… if anyone knows better solution please post. Thanks