Just need help with coding

So I have a script on my player that can control which sprite sheet SpriteRenderer uses to render my player.
ReSkinAnimation (Name of the script) spriteSheetName (public float name)

I need my script to do this:

if player is in scene = home change spriteSheetName to HomeClothes
if player is in scene = outside change spriteSheetName to OutsideClothes

Please help me correctly code this script. I’m quite new and I can’t really code with c#. Please forgive me for my stupidity :stuck_out_tongue:

Question, how does your game work? If the player is not in the scene, you will not be able to see him so does it matter if you change clothes?

My player is in the scene. (If my player goes to the house - he gets removed from the other scene)

Sorry, totally misread your post. I saw ‘if player is in the scene’ and ‘if player is not in the scene’
Next question, what defines your home and outside? Is it a 3d game or 2d game?

It’s posted in 2d forum…

Home is defined by scene named ‘home’
Outside is defined by scene named ‘main’

Sorry, it’s still early in the morning but you could do something simple like this:

Scene scene = SceneManager.GetActiveScene();
if (scene.name == "home") {
  // change clothes
}
else if (scene.name == "main") {
  // change clothes
}

OR you can skip that logic above and just change the players clothes when you change the scenes. As you know what scene you are changing too, a script inside that scene can easily change the players clothes.

Then your change clothes function, depending on how your scene objects are set up. You will need a reference to the player or whoevers clothes you want to change. Look a look at the example in:

Thanks, but how can I change my public string to change to a specific name, like outsideclothes or homeclothes?

(If you don’t understand what I meant I have a string that uses a sprite sheet with the name written in the public string to use as a sprite sheet)

Watch this video from 20:40

If your project is set up the same as the videos then you can do something like this.

ReSkinAnimation skinAnim = GameObject.Find("Player1").GetComponent<ReSkinAnimation>();
skinAnim.spriteSheetName = "blah blah blah"; // You can change the name of the sprite sheet here by changing the text

Can’t thank you enough :):):):):):slight_smile: