Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Oct 21, 2014 at 07:16 AM by bobin115 for the following reason:

solved

avatar image
0
Question by bobin115 · Oct 20, 2014 at 12:01 PM · collisionhide

hide child object script - help

hi all,

i have been playing around with this script for a longtime and it still doesn't work, what is suppose to happen is my player collides with the trigger, "B" is pressed then the CHILD of the object to hide, here is myscript

 function OnTriggerStay(trigger : Collider) {
      if((trigger.gameObject.tag == "Player") && Input.GetKeyDown(KeyCode.B)) {
       renderer.enabled = false;
     }
 }


how would i change this script so that it hides the child object?

any help/ amendments would be great

thanks

Comment
Add comment · Show 3
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 Wisearn · Oct 20, 2014 at 12:10 PM 0
Share

Try adding a Debug.Log("it works"); where you have renderer.enabled = false to see if it even gets that far.

avatar image bobin115 · Oct 20, 2014 at 12:13 PM 0
Share

im not familiar with debuglogs, however i do have similar script for sound and that works

avatar image Wisearn · Oct 20, 2014 at 12:16 PM 0
Share

if you write Debug.Log("hello"); anywhere, it will print out hello in the Console of the unity editor when it reaches that part of the code.

1 Reply

  • Sort: 
avatar image
0

Answer by Phantomized · Oct 20, 2014 at 12:25 PM

There's nothing wrong with the code.

Try to make sure of the following:

Is the player character tagged as "Player"

Does the player character have a rigidbody attached?(it should)

Does the player have a collider?(it should)

Does the Object to be hidden have a collider?(it should)

is the collider on the object to be hidden set to "IsTrigger"?(it should)

Comment
Add comment · Show 6 · 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 bobin115 · Oct 20, 2014 at 12:34 PM 0
Share

the player is tagged as "Player"

im using a basic charter controller (so no ridged body)

the player does have a collider

the object to be hidden has a collider

the object to be hidden is marked as trigger

avatar image Phantomized · Oct 20, 2014 at 12:52 PM 0
Share

I copied your code directly to my unity, and it worked, so you can be certain that it has to do with something else. What you are saying should work in my eyes. Have you put the script on the object that should disappear? Other problems could be multiple colliders on an object etcetera.

avatar image bobin115 · Oct 20, 2014 at 12:57 PM 0
Share

ah yer it does work, but it doesnt hide the child object

avatar image Wisearn · Oct 20, 2014 at 12:59 PM 0
Share

If you want to hide the child objects then you can do:

 foreach (Transform child in gameObject.transform) {
     child.renderer.enabled = false;
 }
avatar image b1gry4n · Oct 20, 2014 at 12:59 PM 0
Share

then you need to turn off each child renderer with GetComponentsInChildren()

Show more comments

Follow this Question

Answers Answers and Comments

29 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

Related Questions

Multiple Cars not working 1 Answer

hide object start script 4 Answers

GUI cale and position according to the actual screen resolution. 1 Answer

Detecting whether a player is touching the ground 1 Answer

Raycast Destroys player. 1 Answer


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