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 /
avatar image
0
Question by AnthMurphy · Apr 13, 2017 at 12:47 PM · javascriptguimaterialcolor

Changing the tint colour of materials

 EDIT: I have now got the script working but it's makes the material a instance, and doesn't change all the meshes with this material on. 
 
 So i'm trying to achieve something which I thought'd be really simple but turns out to be very difficult. My game object has 4 seperate materials attached to different sections. I want to be able to change the tint colour of each or replace the material to another preset through UI. Here's in code what i basically want it to do : 

 #pragma strict
 
 var rend : Renderer;
 var Blinn1 : Material;
 var Blinn2 : Material;
 var Blinn3 : Material;
 var Blinn4 : Material;
 
 
 
 function Start () {
     
 }
 
 function Update () {
     
 }
 
 function MatYellow(){
 
     rend.material.color = Color(0, 0, 0);
     Debug.Log("yellow");
 }
 
 function MatRed(){
 
     Debug.Log("red");
 }
 
Comment
Add comment · Show 2
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 FortisVenaliter · Apr 13, 2017 at 04:14 PM 0
Share

So... what's the problem? You need to explain the difference between the expected behaviour and the observed behaviour before we can make a diagnosis.

avatar image AnthMurphy FortisVenaliter · Apr 13, 2017 at 05:12 PM 0
Share

The script is being called, but can't figure out how to actual make it replace the existing material, i think the problem is in gameObject.GetComponent.().materials[0] = $$anonymous$$at_yellow;, i'm unsure on the correct way to do this. Also I'm unsure on how to do this on an objcet which has more than 1 material attached to different sections of the same mesh.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FortisVenaliter · Apr 13, 2017 at 05:14 PM

For MeshRenderers with only one material:

 renderer.sharedMaterial = newMaterial;

For MeshRenderers with multiple materials:

 Material[] mats = renderer.sharedMaterials;
 mats[i] = newMaterial;
 renderer.sharedMaterials = mats;
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 FortisVenaliter · Apr 13, 2017 at 05:33 PM 0
Share

And in reply to your new edit:

When you use Renderer.material, it instantiates a new one.

When you use Renderer.shared$$anonymous$$aterial, it applies to all.

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

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

If statement checking material tint color 0 Answers

how to change material color for player customization. 2 Answers

How to change value from shader 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