Changing between sprite-slices using code
Hey! I feel this is pretty basic, but I couldn't find an answer that seems to help me, and I have only a basic understanding of Unity so far. Please bear with me!
Basically, I created a sprite-sheet for a character that can walk in all eight directions, and that sprite-sheet has sprites for each direction the character is facing. I already sliced the sprite-sheet up, and each single sprite is available to me now.
Now I'm just curious how, in C#, I can make the Sprite Renderer change the current sprite to the one I desire. So for example, when I press the left key, I want the game object to change the current sprite to a slice I called "left01," a sprite of the character looking to the left.
I thought I was onto something with GetComponent().sprite, but that only seems to adress the sheet, not individual slices. What should I do?
Thanks in advance!
Your answer
Follow this Question
Related Questions
Sprites have discolored patches / color bleeding 0 Answers
Should I choose high resolution sprites for 2D pixel graphics? 0 Answers
Sprites dull and transparent, irregular shape. what do I do? 0 Answers
How do I get the Box Collidor to form around the shape of the Sprite? 2 Answers
Getting name of Spritesheet on runtime with C#? (Not individual SpriteName) 1 Answer