- Home /
load and switch sprite tiles programatically?
Hi, i am trying to create a top down game where a player's appearance can be changed dynamically during run time, as they switch armor, weapons, etc. to do this, i need to combine different sprites based on in-game actions.
for example, if the player switches weapons, i would keep the same armor sprite, but load a different weapon sprite and display that instead.
i plan on having all these sprites (Armor, weapons, etc) saved as tiles. right now, i'm simply trying to load a sprite tile i've created, and switch between tiles (select which tile to display) in the update method. however, i'm unable to do so. i don't know how to switch tiles:
 public class Main : MonoBehaviour {
     SpriteRenderer rend;
     Sprite backSprite; 
 
     void Start()
     {
         backSprite = Resources.Load("tiles", typeof(Sprite)) as Sprite;
         GameObject obj = new GameObject("Wiz");
         rend = obj.AddComponent(typeof(SpriteRenderer)) as SpriteRenderer;
         rend.sprite = backSprite;
     }
 
     void Update()
     {
         //switch between tiles here:
 
     }
 }
does anyone know how to modify this code so that it cycles through all the tiles in my "tiles" sprite sheet? i would also like to be able to select specific tiles so that i can switch to an arbitrary tile in the sprite sheet at any point in time.
thanks!
Your answer
 
 
             Follow this Question
Related Questions
detect collisions based on sprite pixel intensity? 0 Answers
How can I use one 2D sprite with different pivot points? 0 Answers
Translucent sprites appear solid 0 Answers
Background .png image gets a section of it cut off 0 Answers
What is a performant approach to sprite rendering for a 2d hex grid in unity? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                