unity change color of object in script code example
Example 1: unity change text color
GameObject.GetComponent<Text>().color = Color.black;
Example 2: 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 3: unity set material color
object.GetComponent<Renderer>().material.color = newColor;
Example 4: change olour in unity script
SpriteRenderer sr;
void Start()
{
sr = GetComponent<SpriteRenderer>();
}
void Update()
{
sr.color = Color.red;
sr.color = new Color(0,0,0)
}