- Home /
Changing my character's clothes and environment in 2D
I am doing a game which player pressed a f button the environment and character's clothes change. Like a two scene almost fimiliar but I want it to be not seperate scene, I want it in the same scene. I am focusing on a dream theme so when I press f, environment and my character chance a bit to show that dream theme. Is there any guideline or idea which can help me while writing it's code? It is 2d game.
Answer by surfuay · Apr 03, 2019 at 04:19 AM
you could make all the clothing a child of the player and in the player script you just say when you press f it sets some of them active to true and others to false, you could do the same with the environment.
I would put all that in the player script since it's the play that affects the changes.
I can't remember the code off the top of my head but I believe it would be something similar to
//i'd put this in my game manager or some manager script
public bool asleep = false;
void Start()
{
asleep = false;
}
this part would go in my player script
void Update ()
{
Dreaming()
}
public void Dreaming()
{
if (input.getkeydown(keycode.F))
{
//you'll need to access the manager Script, that you put the bool in, here
if (GameManager.gameManager.asleep == false)
{
GameManager.gameManager.asleep = true;
//these clothes are children of the player, the clothes would start as active and the sleepClothes as inActive (you set that in the editor)
clothes.setActive(false);
sleepClothes.setActive(true);
//you'll need to access another script that controls the background here, you'll want to make that script a public static backGround (whatever you name it)
Main.backGround.awakeBack.setActive(false);
Main.backGround.asleepBack.serActive(true);
}
if (GameManager.gameManager.asleep == true)
{
GameManager.gameManager.asleep = false;
clothes.setActive(true);
sleepClothes.setActive(false);
Main.backGround.awakeBack.setActive(true);
Main.backGround.asleepBack.serActive(false);
}
}
}
SO, if i did this I'd have 3 scripts GameManager which controls my overall bools BackGroundManager which would go on my mainCamera for a 2D game Player Script
Your answer
![](https://koobas.hobune.stream/wayback/20220612194626im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to import multiple UV Maps for a mesh into Unity? 0 Answers
How to prevent friction for character along vertical surfaces? 2 Answers
How can I attach clothing to the character? 1 Answer
adding multiple clothes to character,equipting multiple clothes to character problems 1 Answer
Platformer Flipping 0 Answers