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 HarryGodden · Oct 10, 2013 at 06:59 AM · materialcolorchangeslider

using rgb to change color c#

I am trying to change an objects color through 3 sliders that are red, blue and green. i have a code setup where there is 3 Gui sliders that effect floats:

 rSliderValue = GUI.HorizontalSlider(new Rect(25, 25, 100, 30), rSliderValue, 0.0F, 255.0F);
 bSliderValue = GUI.HorizontalSlider(new Rect(25, 50, 100, 30), bSliderValue, 0.0F, 255.0F);
 gSliderValue = GUI.HorizontalSlider(new Rect(25, 75, 100, 30), gSliderValue, 0.0F, 255.0F);

then lower down in my script i have some code that changes the color like this:

 renderer.material.color = Color32(rSliderValue, bSliderValue, gSliderValue, 1);

im getting an error saying: Assets/Color_Change.cs(37,67): error CS0119: Expression denotes a type', where a variable', value' or method group' was expected

can anyone explain why this error is occurring as i cannot make sense of what the error is meant to tell me.

-Thanks, Harry

Comment
Add comment · Show 1
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 Eric5h5 · Oct 10, 2013 at 04:48 PM 0
Share

You don't write "solved" in the title to accept answers. Please watch the tutorial video (link on the right) if you don't know how to use this site.

1 Reply

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

Answer by dorpeleg · Oct 10, 2013 at 07:00 AM

Add 'new' before color:

 renderer.material.color = new Color32(rSliderValue, bSliderValue, gSliderValue, 1);

Because you did not say 'new', the compiler looks at Color32 as the type instead of a value of a type.

So you where trying to make the type Color32 equal to something.

Where you actually need a variable of type Color32 to equal something.

I hope that made it clear.

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 HarryGodden · Oct 10, 2013 at 03:34 PM 0
Share

hey, thanks for your response, but i am now getting another error using that code:

Assets/Color_Change.cs(37,123): error CS1502: The best overloaded method match for UnityEngine.Color32.Color32(byte, > byte, byte, byte)' has some invalid > arguments and this one too: > Assets/Color_Change.cs(37,123): error > CS1503: Argument #1' cannot convert float' expression to type byte'

is this because i am using floats not bytes? and how would i change a float to a "byte" or ins$$anonymous$$d change the slider to output a byte?

-Harry

avatar image CoalCzar · Oct 10, 2013 at 03:37 PM 0
Share

Is there a reason you are using Color32 ins$$anonymous$$d of Color? Color accepts floats between 0 and 1.

avatar image HarryGodden · Oct 10, 2013 at 03:48 PM 0
Share

oh yeah, that fixed it, thanks!

-Harry

avatar image dorpeleg · Oct 10, 2013 at 04:24 PM 0
Share

Please mark as answered them :)

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

18 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

Related Questions

Material doesn't have a color property '_Color' 4 Answers

Changing two different objects renderer colour 1 Answer

Horizontal Slider Normal-Background Change Color Independently 3 Answers

Set base color of a specific material 1 Answer

Change material color at runtime!! 5 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