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 22, 2014 at 06:19 AM by bobin115 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by bobin115 · Oct 20, 2014 at 02:29 PM · triggerchildhide

HIDE CHILD script - help

what i need to happen: when the player collides with trigger and "B" is pressed the child of that trigger hides.

what does happen: i get an error saying " unknown identifier "child""

here is my script;

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

}

any help would be great

thanks

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 RayJr · Oct 20, 2014 at 02:40 PM 0
Share

"child" needs to be declared.

avatar image bobin115 · Oct 20, 2014 at 02:41 PM 0
Share

how would i do that

3 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by Phantomized · Oct 20, 2014 at 06:32 PM

Basically you need to get the child transform(s) first before you can tell its renderer to stop rendering. Here are 2 ways:

If you only have one child to make invisible:

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

If you want to make all the children invisible:

  function OnTriggerStay(trigger : Collider) {
       if((trigger.gameObject.tag == "Player") && Input.GetKeyDown(KeyCode.B)) {
           for (var child : Transform in transform) {
             child.renderer.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 bobin115 · Oct 21, 2014 at 07:15 AM 0
Share

thanks a lot :)

avatar image
0

Answer by RayJr · Oct 20, 2014 at 03:03 PM

Sorry, that was a lame response :P

Basically, when you hit the trigger, you need to go get the child/childern then you can do stuff to them.

this post explains how to get the childern from the parent.

http://answers.unity3d.com/questions/689549/find-child-objects-by-name.html

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 bobin115 · Oct 20, 2014 at 05:31 PM 0
Share

how would i incorporate this into my script?

avatar image
0

Answer by spiceboy9994 · Oct 20, 2014 at 04:14 PM

Not sure that actually Child exist. Have you tried Transform.GetChild?

http://docs.unity3d.com/ScriptReference/Transform.GetChild.html

Another thing that may help you is try to print the name (or the tag) of the element that is triggering the function, just to be sure that the object has a rendered attached to it.

Regards

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 bobin115 · Oct 20, 2014 at 05:17 PM 0
Share

how would i incorporate this into my script?

Follow this Question

Answers Answers and Comments

30 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

Related Questions

hide object start script 4 Answers

GetComponentInChildren(Renderer).active wont work? 2 Answers

Play parent animation without affecting the child animation 1 Answer

hide child object script - help 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 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