- Home /
Load specific sprites from SpriteAtlas into array
Hello,
First of all, I'm sorry if this has already been asked - I could only find one thread with a similar question, but without a useful answer.
So - my question is fairly simple.
I have a SpriteAtlas with a bunch of sprites of cars inside of it.
Sprite names could be:
RedCar_1
RedCar_2
BlueCar_1
BlueCar_2
I also have PreFab sprite named "Car". The PreFab has a component named "CarTextures" (where a public string CarColor is present). The script is supposed to do this:
In Start() method the script should look on in CarsSpriteAtlas and find any sprites which contains the CarColor entered in the Inspector.
So for instance, if the CarColor is set to blue it should look up sprites which name contains blue and then pass it into an array and set one of the found sprites as the current texture.
Most of the stuff I already figured out, but I cannot seem to figure out how search the SpriteAtlas for specific sprites.
If anyone can point me in the right direction I'd be a smiley face.
Best wishes, Cooper
Answer by coopercoding · Feb 15, 2021 at 08:53 PM
I came up with a thought. Would it be better to skip the SpriteAtlas and then make a GameObject with all of the textures in - and then handpick the ones I need? I fear this might be increasing memory used.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Overlapping shape detection 1 Answer
Turning GIFs to spritesheets IN UNITY 1 Answer
does the PSD importer come with source code ? 0 Answers
Socket programming in unity 3 Answers