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 kylehlogan · Apr 25, 2013 at 06:28 PM · lightinginspectorcolorrgb

Issues with changing light colour

If I have something like,

   if (counter == 10.0F)
   {
     light.color = Color.blue;
   }

But I want to change 'light.color' to a value that I've managed to find in the Inspector by dragging the selector around, how would I use the RGB values from this and apply them to the code? I've had a look at some documentation and answers and I can't find anything that will let me do this, it just seems to be 'Color.whatevercolour'. The RGB value that I want to use is '180/63/255'.

It seems like a really basic thing but I'm just having a bit of difficulty from it, I'd really, really appreciate it if anyone can help me do this.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by AlucardJay · Apr 25, 2013 at 06:59 PM

The Color parameters are between 0 and 1 , not 0 and 255 =]

Each color component is a floating point value with a range from 0 to 1. :

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

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

I'm assuming C# from your code snippet. If you already have a colour variable in the Inspector, can you not simply assign the variable to the light colour?

 public Color myColour;

 void SomeMethod()
 {
     if (counter == 10.0F)
     {
         light.color = myColour;
     }
 }

or using your chosen values :

 void SomeMethod()
 {
     if (counter == 10.0F)
     {
         float r = 180.0f / 255.0f;
         float g = 63.0f / 255.0f;
         float b = 255.0f / 255.0f;
         light.color = Color( r, g, b );
     }
 }
Comment
Add comment · Show 2 · 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 kylehlogan · Apr 25, 2013 at 07:14 PM 0
Share

Yeah, C#. Thank you!

avatar image Petomai · Aug 01, 2016 at 07:51 PM 0
Share

I did light.color = Red; but it says unknown identifier Red.

avatar image
1

Answer by Lazy08 · Apr 25, 2013 at 06:51 PM

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

C#:

 if(counter == 10.0F)
 {
     Color prettyColor = new Color (0.706F, 0.247F, 1.0F);
     light.color = prettyColor;
 }


What you do is get your RGB value and divide it by 255. Store these values in a Color variable. Then set your light.color to the variable.

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 kylehlogan · Apr 25, 2013 at 07:14 PM 0
Share

Works perfectly, 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

14 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

Related Questions

Colors Seem all wrong when I set them in RGB 2 Answers

Find out RGB in Viewport 1 Answer

How to assign a color shown in the "Color" window to a color field in the inspector? 6 Answers

rgb value detail 0 Answers

Custom color for properties in Inspector. 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