x


Changing tint color of skybox via script

I'm trying to access and change the tint color of my skybox via my script. I've read some other questions on unity answers on this but unfortienly they didn't help me at all. I'm trying to reach the RGB via the script. Can anyone give me a few or atleast one detailed example of how to do this. This is what i tried...

skyBoxName.color.g = 30;

But i got "Cannot modify a value type return value of `UnityEngine.Material.color" error

Thanks for reading!

more ▼

asked Jun 22 '12 at 04:08 PM

SimonTheDiamond gravatar image

SimonTheDiamond
1 3 3 3

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

This is how the tint color is declared in the skybox shader :

Properties {
    _Tint ("Tint Color", Color) = (.5, .5, .5, .5)
    // other stuff
}

Unfortunately, material.color is a property declared like that in Unity (because _Color is usually the name you give to the main color) :

public Color color{
    get{ return GetColor( "_Color" );
    set{ SetColor( "_Color", value );
}

This, with the fact that you can only assign a complete color to the property and not modify r,g,b, or alone, is why your code isn't working. Finally, Color's values are between 0 and 1, not 0 and 255. Here is the solution : (js)

skyBoxName.SetColor( "_Tint", Color( 0.0, 30.0 / 255.0, 0.0, 1.0 ) );
more ▼

answered Jun 22 '12 at 04:17 PM

Berenger gravatar image

Berenger
11k 12 19 53

Thank you so much! Think you can translate it to C#? I'm not that experienced as you can see yourself.

Jun 25 '12 at 06:43 PM SimonTheDiamond

Come on, one line isn't so hard ;) You need to add a 'new' somewhere and 5 'f'.

Jun 25 '12 at 06:59 PM Berenger

I solved it, haha! Thank you so much!

Jun 25 '12 at 07:42 PM SimonTheDiamond

Thanks for that answer!

Jul 23 '12 at 09:30 AM zerebruin
(comments are locked)
10|3000 characters needed characters left

skyBoxName.color = Color( red, green, blue )

You can't directly set the r,g,b values, they're just for reading.

more ▼

answered Jun 22 '12 at 04:13 PM

Loius gravatar image

Loius
10.7k 1 11 41

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3340
x510
x162
x25
x4

asked: Jun 22 '12 at 04:08 PM

Seen: 1193 times

Last Updated: Jul 23 '12 at 09:30 AM