Answers for "unity c# change color of gameobject"

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

unity c# change color of gameobject

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 June-13-2021

Code answers related to "unity c# change color of gameobject"

C# Answers by Framework

Browse Popular Code Answers by Language