• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Dqimass · Apr 05, 2016 at 10:23 AM · c#unity 5playerontriggerenter2dtransform.parent

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fredex8 · Apr 06, 2016 at 01:57 AM 0
Share

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...

avatar image Dqimass Fredex8 · Apr 07, 2016 at 08:10 PM 0
Share

Sorry you're right! thanks for the re$$anonymous$$der

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Gamesearch · Apr 07, 2016 at 08:23 PM

  1. Give your Player GameObject the Tag "Player".

  2. Go to the GameObject which will be used as "The Invisible Trigger" and set in the Collider component the: is Trigger = on.

  3. 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;
        }
    
    
    
    
    
    
    
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dqimass · Apr 08, 2016 at 12:01 AM 0
Share

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?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I isolate just the character to slow down 0 Answers

how do i get my player get sucked into a gameobject 2 Answers

How do I have my character aim where my mouse cursor is? 2 Answers

Physics2D.OverlapBox (C#) 0 Answers

How do I trigger a particle effect on the player after a timer script deactivates the player gameobject? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges