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 IndieHood · Jul 23, 2013 at 07:03 PM · javascriptcollisioncolor

Changing a Game Object's RGBA Value on Collision (JS)

I have a cube (Player) I want it to change color upon collision which I have I have achieved using

  function OnTriggerEnter 
   
   (Player : Collider)
   
     {
         
         Player.gameObject.renderer.material.color = Color.green;
     }

This works well but I am trying to change the object color with more control using RGBA. After digging around the forums I tried this: function OnTriggerEnter

   (Player : Collider)
   
     {
         
         Player.ObjectName.renderer.material.SetColor("_TintColor", Color(23, 2, 13, 2));
     }

This has no problems running but there is no change of color on collision - can anyone help point out where I am going wrong! Much appreciated!

Cheers

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 Seth-Bergman · Jul 23, 2013 at 07:13 PM

Color is a struct, and can be used the same as a predefined color (like Color.green):

 Player.gameObject.renderer.material.color = Color(.23,.2,.13,.2);


Comment
Add comment · Show 3 · 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 IndieHood · Jul 23, 2013 at 08:29 PM 0
Share

Seth,

I am working with the following code now and on collision the object simply disappears (maybe the same as the background colour)

  function OnTriggerEnter 
   
   (Player : Collider)
   
     {
         
         Player.gameObject.renderer.material.color = Color(242,118,73,100);
     }

Any thoughts?

avatar image Seth-Bergman IndieHood · Jul 23, 2013 at 08:41 PM 0
Share

first off, please don't post comments as new answers, just use the comment tab.

now, see here:

http://docs.unity3d.com/Documentation/ScriptReference/Color-operator_Vector4.html

(and here)

http://docs.unity3d.com/Documentation/ScriptReference/Color.html

color values range from 0 to 1, adjusted..

(also, if my answer [or any answer] does solve your issue, please remember to check the mark to accept it..)

and finally, welcome to the forums!

avatar image IndieHood · Jul 23, 2013 at 09:46 PM 0
Share

Thanks Seth, worked out to just divide the RGB number by 256 which would give me the integer that I needed - working fine now thanks!

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

16 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

Related Questions

Custom Collision Detection 4 Answers

On collisionenter name == redblock 0 Answers

Detecting the Green in a Material's Color on Collision 1 Answer

How to check if car entered garage... then if true, do a specified function ? -1 Answers

Collision not working. 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