Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by JohnBrick · Apr 25, 2018 at 05:31 PM · rigidbodyfps controllerbox colliderenable and disable script

How to hide a Game Object on collission?

Heys guys,

I hope somone can help me with this:

I have a Game Object "A" and a RigidBodyFPSController with a Box Collider "B" with Mesh Renderer turned off. When the Player collides with "B" I want to deactivae/hide "A" and as soon as the Player exits the Box Collider "B" the Game Object "A" should be visible again.

Who has mercy with my noob-question and can provide a script for that? You would make my day!

Many thanks!

Best John

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by awesomekev · Apr 25, 2018 at 06:14 PM

To read more about collision, I can recommend this tutorial. If you just want to hide "A" you can simply also deactivate the render on collision.

 A.GetComponent<Renderer> ().enabled = false;


Comment
Add comment · Show 2 · 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 JohnBrick · Apr 25, 2018 at 08:56 PM 0
Share

@awesomekev thank you very much for your quick respond. yes, that´s exactly what I would like to achieve - Object "A" should only be deactivated while the Player is collided with "B"

I am still struggling with the correct code. I have checked your tutorial-link as well as the documentation and tried your line of code, but I haven´t achieved the goal.

I am new to Unity and looks like I am doing something wrong. Could someone show me what am I doing wrong here?

Which results in this error: "Can´t add script component "RenderOff" because the script class cannot be found. $$anonymous$$ake sure that there are no compile errors and that the file nam and class name match.

Here is the Code I try to attach.

using UnityEngine; using System.Collections;

public class DestroyCubes : $$anonymous$$onoBehaviour { void OnCollisionEnter (Collision col) { if(col.gameObject.name == "B") { Destroy(col.gameObject); } } }

On my Object "B" I have a Box Collider with Trigger turned to on

I would really appreciate some help here!

avatar image awesomekev JohnBrick · Apr 26, 2018 at 07:48 PM 0
Share

For me the error sounds like as if your script name does not match your file name. That means your script class' current name is DestroyCubes then your file name must be DestroyCubes.cs. Is that the case? They have to match for unity to work.

avatar image
0

Answer by JohnBrick · Apr 29, 2018 at 06:41 PM

hi, thx for your response I already fixed it by using GameObject.Find ("A").transform.localScale = new Vector3 (0, 0, 0);

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 awesomekev · Apr 29, 2018 at 06:42 PM 0
Share

Glad you could find it out!

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.

Follow this Question

Answers Answers and Comments

107 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Compound colliders are acting strangely 1 Answer

Rigidbody FPS controller? 0 Answers

Cant get Collisions to work 3 Answers

Laggy FPS Camera (attached to rigid body player), I have tried everything. Unity wizards need to be summoned for this one. 0 Answers

How can I get a responsive rigidbody FPS controller without acceleration that reacts to forces? 2 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