Need a script to hide the player
I am new to unity and scripts in general so I thought I would learn through trial. And I would greatly appreciate a detailed answer. The game offer the player to hide behind "certain" objects and it's 2D game. So I think I need OnCollisionEnter and buttonDown to destroy the player and the object hiding behind it and replace them with a certain spirit that shows that the player is hiding and of course disable the collider, and when the player takes his hand off the button the character returns to its original state. Thank you.
It sounds like you know exactly what you want the script to do, so why don't you just write it?
Answer by joemane22 · Nov 14, 2015 at 06:22 AM
You got the logic of it correct, but you don't want to destroy your player, it would be easier to just hide it from view. There are multiple ways to do this, the one you should pick depends on your situation.
Using sorting layer
You could set the sorting layer to one that is behind the background so your background draws over your player effectively hiding the player from view. But all other player mechanics will still be active
Set inactive
You could set your players game object to inactive by calling gameObect.SetActive(false). This will stop drawing and updating your character, but it will also stop updating your components as well if I am thinking correctly.
Z position
If you don't have your sorting layers set up you could also move your player around in the Z axis, which will draw it ahead or behind all objects that are ahead or behind the player but all other player mechanics will still be active
Your answer
Follow this Question
Related Questions
How do you stop capsule from going through walls? 1 Answer
Multiple Floors: how to hide/show a floor when a character is climbing/descending ? 0 Answers
RPG Class Selection Menu 2 Answers
ScriptableObject for units (enemy, monster),ScriptableObjects for units (enemy,monster). 0 Answers
How to make an object that collides with just the player? 1 Answer