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 Volumnia · May 10, 2013 at 12:35 AM · javascriptrendereroncollisionentergetcomponentsinchildrenrenderer.material.color

Changing the renderer.material.color of the children OnCollisionEnter?

First of all, hello all and thanks for reading! :)

I'd like to have my enemy flash red for a brief duration of time, when my spells hit it and then have it go back to its original color.

So far, after numerous tries and hours of research, I've got some result with the method posted [here][1] but it only changed one part of my character at time, and it did not work or look good over all. Not to mention I haven't found a way to get it back to its default look after an x period of time :(

Here's my code:

 var children : Renderer[];
 
 function Start()
 {
     children = GetComponentsInChildren.<Renderer>();
 }
 
 function OnCollisionEnter (collision : Collision)
 {
     if(collision.gameObject.tag == "Spell") 
     {
         
         for(var i : Renderer in children)
         {
             children.material.color = Color.red;
             yield WaitForSeconds(.5);
             print("CHANGED COLORS?");
             
         }
     }
 }
 

Now however, I can't even get the script running because it has been accusing the error: BCE0019 : 'children' is not a member of 'UnityEngine.GameObject'.

Is there any way to make this work?

Thank you all in advance! [1]: http://answers.unity3d.com/questions/64121/how-to-access-child-object-colours.html

Comment
Add comment · Show 4
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 robertbu · May 10, 2013 at 01:33 AM 0
Share

@Chronos-L addressed your compiler error. Beyond that are you sure that all of your materials for all the children have a color attribute?

avatar image Volumnia · May 10, 2013 at 01:49 AM 0
Share

.............. I swear I thought I had used this before.

If I say I am very tired, will you believe me? LOL

THAN$$anonymous$$ YOU! :)

However, I still can't figure out how to change the color back. I tried it with i.material.color = Color.clear; but it only turns it all black, or well, transparent. And I can't use 'null' either. Got any pointers, maybe?

avatar image ByteSheep · May 10, 2013 at 01:51 AM 0
Share

You can store the original colour in a variable before changing it.

 var original_color = i.material.color;
avatar image Volumnia · May 10, 2013 at 02:07 AM 0
Share

robertbu - the red tint seems to work fine, so I guess that means they do have the color attribute.... right? :<

merry_christmas - I guess I stand corrected, since when I tried to store the original color, it returned to me the following: "$$anonymous$$aterial doesn't have a color property '_Color'"

Sighs

What to do? :( And sorry if I am so helpless, guys. I did try to solve this myself, but I couldn't seem to find a solution for this at all...

Edit: typos haunt me.

1 Reply

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

Answer by Chronos-L · May 10, 2013 at 01:23 AM

 for(var i : Renderer in children)
 {
    i.material.color = Color.red;
    yield WaitForSeconds(.5);
    print("CHANGED COLORS?");
 }
Comment
Add comment · 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

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

15 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

Related Questions

how to make object stay destroyed after OnTriggerEnter? 1 Answer

JS Script only work in Editor 0 Answers

Is it possible to change an entity's RenderMesh color in ECS just like the renderer.material.color in monobehavior? 1 Answer

Change gameobject sprite with button 1 Answer

OnCollisionEnter Collision not detected? 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