- Home /
Multiple sprites for game object
Im making a japanese educational game and made this sprite sheet. Ive already sliced it in the sprite editor and named all the symbols.
Im instantiating 5 prefabs that need to have 5 different sprites with different symbols. I thought I was gonna be able to either assign the entire sheet to a game object or just keep adding sprite renderers to the game object, but I was wrong. How can I achieve this?
Answer by darthbator · Jun 10, 2014 at 11:40 PM
A sprite renderer merely refers to a gameobjects ability to render a sprite onscreen. The Sprite rendered is stored in the "sprite" member variable of the SpriteRender class instance. So whatever sprite you load into that slot will be the one rendered. You can make something like an array of sprite objects and then assign an object from there to the SpriteRender.sprite field to have it rendered. You would need some logic in awake or as a constsructor in order to determine which sprite from the array to load.