Changing how my character looks depending on his current lifes.

Hey everyone,

i’m really new to programming and unity, Bu still im quite far with my game. Im doing a 2d platform game in unity. I’m trying to change how my character looks depending on his current lifes status.

For example: if he has 4 lifes he should wear full clothes and if his lifes go down to 2 he only should wear underpants. I already created the animation sprites but i don’t know how to connect them to each other and how to code it.

THX for your help, i appreciate it.

Good day.

I recoomend you te create one prefab for each state, and instantiate the prefab that is needed each time. Then you must have a gameobject without any sprite called for example “Player” with the script called for example “PlayerScript”.

you need to check first the remaining lifes to know what prefab instantitate. Dome something like this:

public GameObject Player4HP, Player3HP, Player2HP, Player1HP;

Then via inspector, assign each prefat to each of this variables. And now only need to instantiate the correctone:

if (Player.GetComponent<PlayerScript>().RemainingLifes == 4)
{
Instantiate (Player4HP, Player.transform);
}
else if (Player.GetComponent<PlayerScript>().RemainingLifes == 3)
{
Instantiate (Player3HP, Player.transform);
}

......

If don’t know somethig of the below functionsm i reccomend you to go read the manuals, look some youtube tutorials, etc…

Good luck!

Bye!

Ok i think i got it. If i’m correct i will create like 4 different players ?

I initiate different ones depending on their lifes ?