Player hiding inside Gameobject
Hey guys, sorry I've been searching and trying a whole lot of scripts and going through lot of tutorials for 3 hrs and I can't seem to find what I need so I hope I can find my answer here. Please help >< and then i'll try figure out the next move. I didn't want to destroy the player cause I wanted the camera to follow the player since it's going to be a scrolling screen game.
I thought the OnTriggerEnter would do the trick, but it doesn't do anything, maybe i used it wrong T.T Also i tried Transform.Parent. and it didn't seem to work either.
update: Sorry! I didn't post any question here! thanks for the reminder Fredex8 The question is How do I make my player hide inside an Gameobject like.... Rocket, Cannon, or Barrel. The Gameobject is currently moving Up and down, so i wanted my Player to disappear when it collide with the GameObject. What I'm trying to do is having my character jump into a object, the object carry the player up and down, and then Fire the player (with a button pressed) forward with force.
Did you forget to post something? Currently you will not be able to find your answer here because you haven't really posted a question...
Sorry you're right! thanks for the re$$anonymous$$der
Answer by Gamesearch · Apr 07, 2016 at 08:23 PM
Give your Player GameObject the Tag "Player".
Go to the GameObject which will be used as "The Invisible Trigger" and set in the Collider component the: is Trigger = on.
Make a Script an add the following Part to it. Give the Invisible Trigger the Script and you´re good to go!
void OnTriggerEnter(Collider other) { GameObject.FindGameObjectWithTag("Player").GetComponent<MeshRenderer>().enabled = false; }
Thanks Gamesearch! This works perfectly. i also got the Player to follow the object but i have one problem. I'm using this code
void OnTriggerEnter2D (Collider2D other) { GameObject.FindGameObjectWithTag("Player").GetComponent ().enabled = false;
if (other.gameObject.CompareTag ("Player"))
other.transform.parent = gameObject.transform;
the player is following the floating object np, but since the gameobject is also rotating constantly, the player Rotate too around the object. It's like being thrown around in circle. Anyways I can prevent the player from rotating?