Best way to change 2D sprite based on state?

I’m trying to figure out the best way to do this in Unity.

Let’s say you had a face object:
:slight_smile:
And you wanted to change it into a laughing face:
:lol:

Would you destroy the first object, and create a second object in it’s place?

Or would you have one face object and simply change materials based on state?

Hi Tonyd,

I read your question and it appears to me that you have an object that has a material with a texture applied. If you want it to have animation states you’ll need to look at the script here: unifycommunity.com

Animating a tiled texture would be the method I would use for a simple funny face like you mentioned, but it can get pretty advanced. Pay attention to the first sentence under Usage, “Attach this script to the object that has a material with the animation cell-sheet texture. From your other script call this script’s SetSpriteAnimation() function with the new parameters.” Tell me if that works for ya.

Perhaps my post was poorly worded. Or maybe my subject heading!

I know how to do 2D animations, I wrote my own script to handle them before I had even purchased Unity.

What I’m asking is, how do Unity developers normally handle objects with multiple states?

If I was programming in python, I would create a face object with multiple states and display different animations based on state.

If I was working in Game Maker, I would probably create a separate object for each state (especially if changes in state lead to changes in behavior) and simply change them into different objects as needed.

Since I don’t know how to do the second method in Unity, I decided to use method #1 for my first game. Seems to be working so far.

At any rate, thanks for the response!

Hey Tony, I saw your reply and I think I can come up with something. Let me work on it and I will post here in the next day or so.