- Home /
Get sprites from a Texture2D
Hi,
Im using UnityEdtior to get sliced sprites from a texture 2D. This texture is a tileset and each tile is used to build like a RPG map. I sliced all texture on Sprite Editor from Unity. The code below works properly and take me a sprites array, however it cannot be used to compile for mobiles because UnityEditor codes cannot be package.
//texture is an instance of Texture2D
var texturePath = UnityEditor.AssetDatabase.GetAssetPath(texture);
//get all generated sprites from a sliced textured.
var sprites = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(texturePath).OfType<Sprite>().ToArray();
How can I accomplish it without have to use UnityEditor? I need it to build maps on the fly. Thanks!
Answer by Xeong-Hu · Mar 23, 2015 at 07:30 PM
Idk much about IOS games so idk if this'll work but i'll recommend it anyways.
Just make your public sprite an array like this.
public Sprite[] TileImages;
Then when ever you click at the tile you want in Gameplay mode or how ever you wish to change the tiles. This should happen.
Tiles.GetComponent<SpriteRenderer>().sprite = TileImages[4]
Simply change the number of the TileImages array and bam. You're set.
Your answer
Follow this Question
Related Questions
Unity 5.6 Creating a Distortion in Sprites? 1 Answer
How to optimize multiple sprites,How to optimize multiple sprites? 2 Answers
2D optimisation - mobile devices 0 Answers
High resolution background on mobile 0 Answers
Unity iOS memory usage 0 Answers