Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Jun 01, 2016 at 07:37 AM by CBRZY for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by CBRZY · Jun 01, 2016 at 06:05 AM · shaderlightingmaterialcolorrenderer

Changing the color at runtime is causing my material to look very different.

So currently I have a game object that is making use of a material with a "Legacy Shaders/Diffuse" shader and the main color is (255, 0, 0, 255) which is perfect and looks like this: alt text

but I would like to change the color as the player progresses to the next level which I have done, the problem is when I apply the new material the game object looks completely different, it looks like this: alt text

All my lights' Baking attribute are set to Realtime.

This is how I change the color:

 Material material = new Material(Shader.Find("Legacy Shaders/Diffuse"));
 material.color = new Color(255, 0, 0, 255);
 Renderer rend = GetComponent<Renderer>();
 rend.material = material;

Any help would be greatly appreciated.

capture1.png (3.8 kB)
capture2.png (4.7 kB)
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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by allenallenallen · Jun 01, 2016 at 06:44 AM

Your 4 lines of code should just be 1 line if all you are changing is the color. You shouldn't need to assign a new material.

 GetComponent<Renderer>().material.color = new Color(1, 0, 0, 1);

See if that changes anything.

Comment
Add comment · Show 3 · 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 CBRZY · Jun 01, 2016 at 07:08 AM 0
Share

Ok I replaced all my lines with yours and it still does the exact same thing. I started playing around with different shaders and I found that the "Unlit/Color" shader is basically what I am ending up with when I change the color with either my or your code. It kind of looks like the material is losing some attributes when changing the color, well that is all I can think of at the moment.

avatar image allenallenallen CBRZY · Jun 01, 2016 at 07:12 AM 1
Share

Huh, that's weird. $$anonymous$$aybe you need to reimport the shaders? The original shader of that object is Legacy Shaders/Diffuse, right?

Oh and, this might fix the color: https://docs.unity3d.com/ScriptReference/Color.html

It's new Color(1, 0, 0, 1) and not 255 because this is the new Color API.

avatar image CBRZY allenallenallen · Jun 01, 2016 at 07:33 AM 0
Share

Perfect. Thank you very much. The problem was the old api that I thought I was using. $$anonymous$$aking use of Color(1,0,0,1) is what I needed.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Changing two different objects renderer colour 1 Answer

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

Reduce Skid Mark Alpha Gradually 0 Answers

Unity 3d Lights, Shadows and material of objects? 1 Answer

Shader to partially ignore lighting (Specific colors) 0 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