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;
        }    
    }
}

4.5
4

                                    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&lt;Renderer&gt;();

       //Call SetColor using the shader property name &quot;_Color&quot; and setting the color to red
       cubeRenderer.material.SetColor(&quot;_Color&quot;, Color.red);
   }

4.5 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to change the colour of an gameobject to white in unity c' how to change the colour of an gameobject in unity c' how to set color to an object in unity set 3d gameobject color unity unity how to change color gameobject how to change gameobject colour at run time unity how to change color of gameobject in code unity how to change the colors of gameobject continously in unity 3d how to change an object's color unity change colour of unity change unity color color change game using unity how to change the color of objects unity unity game object change color change gameovbject color unity c# unity color for object how to change colour in c sharp unity unity get color of gameobject how to change a objects colour in Unity using code unity change color using #color code HOW TO MAKE OBJECTS CHANGE COLOR THROUGH SCRIPT UNITY set a objects color unity How to change the colour of an object unity change color object unity change colour of object unity how to change the colour of objects in unity using script unity how to change color unity change color of object\ unity change colour of object change color of a gameobject unity unity how to change current objects color Unity game object color unity change game object color with script how to change the color of a gameobject how to set color in c# unity hwo to change color of object in unity with code how to change an onjects color in unity how to change colour of objects in unity unity set gameobject color to white how to change the color of a object in script in unity set custom color c# unity unity change color of an object unity how to change object color c# unity change color script how to change color of object in unity how to change color of an object in unity how to change color in unity unity assign color to gameobject how to change color unity unity set color of gameobject change color of an gameobjct unity with c# unity change color unity change color object how to change the color of objects in unity how to change object color in script unity change color of an object in unity how tho cahnge color of gameobject in unity unity how to change color of object in script change a color in unity unity new colorobject unity changing the color change color of object unity unity change object color change color on unity How can I change the color of a gameobject unity script how to change color of object in unity with code HOW TO CHANGE THE COLOR OF A 3D OBJECT UNITY unity set color how to set a gameobject color unity how to change colour of an object in Unity change color of 3d object unity how to change a certain color in unity c# unity color object how to change color of a gameobject in unity how to change the color of 3d objects in unity how to change an objects color in unity unity changing object color Unity GameObject to color unity change the colour of an object change color of texture unity change color unity unity how to change color of object unity how to change a color of an object how to put color into gameobject unity unity color gameobject unity color game object change object color in unity unity c# how to change 1 gameobject color change colour of gameobject unity inspector how to change color of gameobject in unity change gameobject color unity change color unity object how to change the colour of a 3d gameObject unity in c# change object color unity change color of current object unity script Unity change the color of a gameobject color an object unity unity how to change the colour of an object change color gameobject unity change object colour unity how to change the color of a 3d object in unity how to change colour of object in unity unity change color of object unity change color of object script how to change color of an object in unity using scripting set object color unity change color c# unity change color of object unity script how to change color of 3d object in unity gameobject color unity change the color of an object in unity how to change 3d object color in unity unity change bojects color chaneg objects color unity how to change the colour of an object in unity cant change color of gameobject unity how to change color of gameobject unity how to change the color of a gameobject in unity unity gameobject color unity change color of gameobject change colour of gameobject unity how to change the color of a object c# how to give a object color in unity how to make objects change color unity gameobject change color unity change color gameobject unity c# how to change the color of a button in unity c# change object color c# unity how to change a gameobject color in c# unity How to add color to an Unity object change color of component unity how to change the color of an object in unity c# script how to change the color of an object in unity c# how to change the color of an object in unity Change colo of object unity c# change gameobject color unity c# unity change color of object in script how to change the color of a gameobject through script in unity unity change visibility of gameobject using color change color unity c# how to change the color of a gameobject in unity through code how to change the color of a gameobject in game unity unity C# how to a gameobjects color unity change gameobject color how to change a color of an object in unity script how to change a color of an object in unity scripte gameobject.setcolor how to change material color in unity unity changing a gameobjects color unity change gameobject color code edit colour gameobject unity unity gameobject sert color chagne color of object unity c# unity how to change material color in script change object color unity c# change gameobject color in script unityy change color of object unity c# change color of gameobject unity c# change color of material unity change color of gameobject unity set gameobjects color unity set color of gameobject unity unity c# change color of gameobject
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source