- Home /
 
 
               Question by 
               Shannon847 · Feb 28, 2021 at 01:09 PM · 
                materialscripting beginnermaterialsmaterial color  
              
 
              Getting value of material and applying it to another material through code
Hi, I've been changing the color of a material with a script and would like to make a second material get the same color as the first material on command. How would I go about doing this? Example 1 Shows how I currently Change Color1. Example 2 is my attempt at trying to make Color2 the same as Color1 on command.
 public Material Color1;
 public Material Color2;
 
 public void Example()
 {
 Color1.SetColor("_Color", Color.blue);
 }
 
 public void Example2 ()
 {
      Color2 = Color1;
 }
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Llama_w_2Ls · Feb 28, 2021 at 01:38 PM
After you've set the color, can't you just assign it to material 2 like this:
 public Material myMat;
 public Material secondMat;
 
 void Example2()
 {
      secondMat.color = myMat.color;
 }
 
                
              Your answer