How to add color to an Unity object 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: set object to random color unity
[RequireComponent(typeof(Renderer))]
public class colorTint : MonoBehaviour
{
public List<Color> TintColors;
void Start()
{
Color c = TintColors[Random.Range(0, TintColors.Count)];
GetComponent<Renderer>().material.color = c;
}