change color unity code example

Example 1: unity c# change color of gameobject

using UnityEngine; 
using System.Collections; 

public class collisionpill : MonoBehaviour 
{      
  	public Color mycolor;       
  	
  	void OnCollisionEnter(Collision other) 
    {         
        if (other.transform.tag == "Pill") 
        {             
        	gameObject.GetComponent<Renderer>().material.color = mycolor;
        }    
    }
}

Example 2: unity set material color

//Gets the renderer material and sets color
object.GetComponent<Renderer>().material.color = newColor;

Example 3: change olour in unity script

SpriteRenderer sr;

void Start()
{
	sr = GetComponent<SpriteRenderer>();
}
void Update()
{
	//This is a simple way of adding color
	sr.color = Color.red;
	//This is a more specific way of adding color
    sr.color = new Color(0/*Red*/,0/*Green*/,0/*Blue*/)
}

Example 4: how to change the color of an object in unity c# rgb

void Update ()
             {                         
               if(Input.GetKeyDown(KeyCode.R))
               {                                 
                 gameObject.GetComponent<Renderer>().material.color = new Color(233, 79, 55);
               }             
             }