• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by rustyruss1985 · May 09, 2018 at 09:02 PM · spritesspriterenderersprite-animationsprite sheets

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

85 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Sprite Renderer & UI Image bad Sprite quality 2 Answers

how can i access multiple sprites using a single variable? 1 Answer

Unity 2D problem with displaying sprites in final build game 1 Answer

Animated sprite's bounds not in sync with its visuals 0 Answers

How do I set a sprite to fill the entire screen in UI? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges