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
1
Question by SimonTheDiamond · Jun 22, 2012 at 04:08 PM · colorskyboxchanging

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!

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
6

Answer by Berenger · Jun 22, 2012 at 04:17 PM

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 ) );
Comment
Add comment · Show 4 · 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 SimonTheDiamond · Jun 25, 2012 at 06:43 PM 0
Share

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

avatar image Berenger · Jun 25, 2012 at 06:59 PM 1
Share

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

avatar image SimonTheDiamond · Jun 25, 2012 at 07:42 PM 0
Share

I solved it, haha! Thank you so much!

avatar image zerebruin · Jul 23, 2012 at 09:30 AM 0
Share

Thanks for that answer!

avatar image
-2

Answer by Loius · Jun 22, 2012 at 04:13 PM

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

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

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Having a changing Skybox depending on location of player 1 Answer

How do I change the font and color of GUI text? 0 Answers

Skybox Discoloration Problem 0 Answers

What's the syntax for creating a skybox with a script? 2 Answers

How do I change the color of a Trail Renderer by script? 3 Answers


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