Answers for "how to change color in unity c#"

C#
4

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;
        }    
    }
}
Posted by: Guest on June-27-2020
1

color change unity

//Attach this script to any GameObject in your scene to spawn a cube and change the material color
using UnityEngine;public class Example : MonoBehaviour
{
   void Start()
   {
       //Create a new cube primitive to set the color on
       GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);       //Get the Renderer component from the new cube
       var cubeRenderer = cube.GetComponent<Renderer>();       //Call SetColor using the shader property name "_Color" and setting the color to red
       cubeRenderer.material.SetColor("_Color", Color.red);
   }
}
Posted by: Guest on August-17-2021
5

unity set material color

//Gets the renderer material and sets color
object.GetComponent<Renderer>().material.color = newColor;
Posted by: Guest on June-13-2020
0

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*/)
}
Posted by: Guest on July-24-2020

Code answers related to "how to change color in unity c#"

C# Answers by Framework

Browse Popular Code Answers by Language