- Home /
Changing a materials color in C#
I've been watching bergzerg arcade's hack & slash tutorial, and at the end of the 9th video he puts in a script that changes the default materials color. I'm using a custom model, with a custom texture/material. There are no errors in the script, and I have searched around on Unity Answers and google but I can't find anything that works. Thanks in advance!
Answer by Ren · Apr 07, 2011 at 03:55 AM
Try this:
C#: mObjectName.gameObject.renderer.material.color = new Color(R, G, B, A);
JS: mObjectName.renderer.material.SetColor("_TintColor", Color(R, G, B, A));
Answer by TheCreeperMiner · Mar 09, 2015 at 11:50 AM
 Sprite spr = Resources.Load<Sprite>("SpriteName");
  SpriteRenderer sprRenderer= (SpriteRenderer)renderer;
  sprRenderer.sprite = spr;
 
 public class ExampleClass : MonoBehaviour {
     public Color colorStart = Color.red;
     public Color colorEnd = Color.green;
     public float duration = 1.0F;
     public Renderer rend;
     void Start() {
         rend = GetComponent<Renderer>();
     }
     void Update() {
         float lerp = Mathf.PingPong(Time.time, duration) / duration;
         rend.material.color = Color.Lerp(colorStart, colorEnd, lerp);
     }
 }
 //make it in javascript 
Your answer
 
 
             Follow this Question
Related Questions
Material doesn't have a color property '_Color' 4 Answers
Changing two different objects renderer colour 1 Answer
I want each face of an object to be a different color 1 Answer
Problem getting prefab color 0 Answers
Color problem 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                