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 /
avatar image
0
Question by Stridulent · Jun 20, 2012 at 05:18 PM · parentchild

Mouseover to use parent and all children?

I have created a simple script that will make objects turn green when hovered over and then back to normal color when mouse exit. I also made it so if selected, the object turns red and stays that way. My problem arises when I have an "object" that has multiple parts, so I combine it into a parent with children and then the script no longer works. Ideally, I would like for it to turn the whole item (parent and children) green when either are moused over.

Here is the script:

 #pragma strict
 
 var selected = false;
 var initialColor : Color;
 
 function Start () {
     initialColor = renderer.material.color;
 
 }
 
 function Update(){
     if (selected == true) {
         renderer.material.color = Color.red;
     }
 
 }
 
  function OnMouseOver() {
     renderer.material.color = Color.green;
 }
 
 function OnMouseExit() {
     renderer.material.color = initialColor;
 }
 
 
 
 function OnMouseDown() {
     if (selected == false && ItemsRemaining.items > 0) { ItemsRemaining.items--; }
     selected = true;
 }
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

1 Reply

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

Answer by whydoidoit · Jun 20, 2012 at 05:23 PM

Let's presume this script is called Boxes:

     function OnMouseOver() {
            var scan = transform;
            while(scan.parent.GetComponent.<Hazards>() != null)
                   scan = scan.parent;
            for(var hazard : Hazards in scan.GetComponentsInChildren.<Hazards>())
                   hazard.renderer.material.color = Color.green;
     }
Comment
Add comment · Show 18 · 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 Stridulent · Jun 20, 2012 at 05:37 PM 0
Share

The script I am using is called Hazards.js and the goal of this "game" is for the player to identify all hazards in a scene. So say I have a bucket with a mop in it, and although they are separate objects, I have child'ed the mop under the bucket. I would like for them both to glow when either are hovered over, which isn't happening, even with your recommended script. Thank you though, hopefully my more detailed description can better relay what I am trying to do.

avatar image whydoidoit · Jun 20, 2012 at 05:39 PM 0
Share

Well this code will work with Hazard too :) I will edit the answer - use something similar in your other routines.

avatar image Stridulent · Jun 20, 2012 at 05:43 PM 0
Share

And I add this script to the parent, right?

avatar image whydoidoit · Jun 20, 2012 at 05:52 PM 0
Share

No you use it for all of them.

Let me explain what it does. You put this on all of them and it works it's way up to find the parent which is the last one that has a Hazard script - then is sets all of the items below it to green...

avatar image whydoidoit · Jun 20, 2012 at 05:53 PM 0
Share

That code was a replacement for your On$$anonymous$$ouseOver() routine in Hazards

Is the parent also a Hazard?

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

Parenting Transforms, Must (still) Set Parent at 0,0,0 ? 1 Answer

how would I "child" an un-rendered object? 1 Answer

Affect child's child from main parent's script? 2 Answers

Child of Parent 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