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 Party Boy · Mar 20, 2014 at 02:16 PM · c#buttoncolorlightintensity

Changing light colour makes it too bright

Hey there. So I'm trying to have different colour spells according to what button you press on the Razer Hydra. I have code that I think should work but obviously isn't and I'm not sure why. When the demo starts the light is way to bright. If I remove the line of code in the Start() method that sets the colour, it is fine and has the right range and intensity that I want. However if I add this code in or change the light colour by a button press, it gets messed up and too bright.

Here is a picture example with the code to see also.

alt text

Thanks for any help with 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

3 Replies

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

Answer by TropicalTrevor · Mar 20, 2014 at 07:04 PM

This code works for me, if I mimick it in a small use case that is:

 using UnityEngine;
 
 
 public class tmp : MonoBehaviour
 {
     [SerializeField]
     Color c = Color.white;
     [SerializeField]
     float i = 0.25f;
 
     void Start()
     {
         //Light light = GetComponent<Light>();
         light.color = c;
         light.intensity = i;
         light.range = 3;
     }
 }

I changed the color in the inspector to various things and it all turned out correctly.

Two things I would like to tell you

Light is multiplicative, if you have a light source that is 100% blue (so new Color(0,0,255);) and put it in a scene that has the default material, everything is blue. But if you create a new material and make the color red (255,0,0) everything will be black. This is because blue * red = black, red contains no blue so blue light only shows the blue part, which is zero. (0*255, 0*0, 255*0) = (0,0,0)

So in short: I think your light color mismatches with your material color making some objects appear correct and other over-bright.

Tips: Make your light look right when the light is white, desaturate your textures so colored lights can influence the world with whaterver color they have and possibly desaturate the lights either way. Colors look bright in comparison to their surrounding, if something is only a little red in a grey world it will still look very red so don't worry about your world becoming too flat - as long as the contrast is right.

Additionally (if you have pro) you can solve the boring-ness of colors by upgrading the saturation with a post effect.

Another, totally unrelated thing, I'd also like to recommend you to use a public or serialized field to put the light in like so (this is not related to your question at all but I just noticed it in your code):

     public class MyClass : MonoBehaviour
     {
     [SerializeField]
     Light spellLight;
 /*
     void Start() etcetera
 */
     }

So you can use drag and drop in the editor instead of using gameobject.find -> which will give problems when you have more than 1 object with this name, possibly one having no light source at all etcetera. Also it is faster on startup and gives better error messages (null reference on the specific property so you know the object that was in there was deleted or has not been filled in etcetera).

Comment
Add comment · Show 6 · 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 Party Boy · Mar 20, 2014 at 08:39 PM 0
Share

@TropicalTrevor Thanks so much for that super in-depth response, really appreciate it and it helped me understand quite a bit! However, the code you provided didn't work for me :S Not sure what I'm doing wrong here but here is the code I have now.

I attached the light that this script is attached to in the inspector as you mentioned above.

Here is a picture of the IDE if you want to see the inspector: http://puu.sh/7CZOm.jpg

 using UnityEngine;
 using System.Collections;

public class ChangeSpellLight : $$anonymous$$onoBehaviour {

 [SerializeField]
 Color LightSpell =  Color.white;
 [SerializeField]
 float intensity = 0.25f;
 [SerializeField]
 Light SpellLight;

 void Start(){

     SpellLight.color = LightSpell;
     SpellLight.intensity = intensity;
     SpellLight.range = 3;
 }

Thanks!

EDIT

I fixed it but in a different way. When I used

 SpellLight.color = LightSpell;

It didn't work and was super bright. However

 SpellLight.color = Color.white;

Worked fine. Any ideas why this is?

avatar image TropicalTrevor · Mar 21, 2014 at 09:01 AM 0
Share

that's an interesting problem, I don't know why this is however you could assign lightSpell in Awake or use a public property so you can edit the value in the inspector.

Are you sure you didn't get an error when assigning LightSpell and then the range and intensity were never set (so probably the range was at 12, the intensity at 1, the color at default, so the light is much brighter because it is much bigger etcetera)?

avatar image TropicalTrevor · Mar 21, 2014 at 01:02 PM 0
Share

found it! stupid for me not to see this... colors range from 0.0f to 1.0f, anything beyond is stored and used so things become ridiculously bright! if you want to use sensible values create a const float COLOR_CONVERSION = 1f / 256f;

avatar image Party Boy · Mar 21, 2014 at 01:31 PM 0
Share

@TropicalTrevor Ah thanks for that. However I'm not understanding this one thing.

If I have this:

 SpellLight.color = Color.white;

And it works, why does having

 SpellLight.color = LightSpell;

Where LightSpell is defined at the top as this:

 Color LightSpell =  Color.white;

Not work? I understand what your saying about having to convert them but would setting them as a color not be the proper way?

Also for what you said about COLOR_CONVERSION, how would I do it for this as an example?

 private Color FireSpell =  new Color(225,113,12);

Thanks

avatar image TropicalTrevor · Mar 21, 2014 at 07:29 PM 0
Share

I don't see why the first bit isn't working (Color LightSpell = Color.white should be fine).

But if you do like this:

 class TestClass : $$anonymous$$onoBehaviour
 {
     const float COLOR_CONVERSION = 0.00390625f; //that is 1/256f;
     Color fireSpell = new Color(225 * COLOR_CONVERSION,
 113 * COLOR_CONVERSION, 12 * COLOR_CONVERSION);
 }


Or maybe even this (not sure if it works though):

 Color fireSpell = new Color(225,113,12) * COLOR_CONVERSION;

you should get the result you want while being able to copy the numbers from Unity or other software's color picker.

So I guess you should check if you don't redefine LightSpell somewhere or whether something else goes wrong there because I can't see anything wrong with the code itself.

Show more comments
avatar image
0

Answer by eran0201 · Mar 20, 2014 at 03:10 PM

Try to set alpha value

 private color PhysicsSpell = new Color(23,118,186,alpha);

or change the intensity

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 Party Boy · Mar 20, 2014 at 06:49 PM 0
Share

@eran0201 That didn't work. Intensity already changed as you can see in the code. Any other ideas?

avatar image
0

Answer by Lord_Slimeball · Jan 31, 2021 at 11:31 AM

Hi, so the solution is here:

https://stackoverflow.com/questions/51439719/how-to-change-unity-lighting-ambient-color-intensity-at-runtime

ambient light values have to be between 0 and 1, 23 for instance is not a valid value

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

23 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

Related Questions

Multiple Cars not working 1 Answer

If statement breaking button color copy 0 Answers

Distribute terrain in zones 3 Answers

UI Button color 1 Answer

Changing light Intensity though script does nothing 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