Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

how to change the color of an object in unity c#

//You can either change material color of an object, or a color of component SpriteRenderer,
//which doesn't really matter unless you have lights added in yout project.

//so lets get a color (blue for this example)
public Color myColor = new Color(0, 0, 1, 1); //(r,g,b,a) 
//changing material color looks like this : 
gameObject.GetComponent<Renderer>().material.color = myColor;

//changing SpriteRenderer color looks like this :
gameObject.GetComponent<SpriteRenderer>().color = myColor;
Comment

change color of object unity

 private Renderer materialRender;

    void Start()
    {
		materialRender = GetComponent<Renderer>();
        materialRender.material.color = new Color(1f, 0f, 1f, 1f); //Color(r, g, b, a)
    }
Comment

PREVIOUS NEXT
Code Example
Csharp :: datetimeoffset to datetime c# 
Csharp :: unity deactivate component 
Csharp :: c# string interpolation 
Csharp :: c# edit element in list 
Csharp :: basic auth swagger .net core 5 
Csharp :: if file exist rename c# 
Csharp :: switch expression c# 
Csharp :: new ienumerable 
Csharp :: unity get default font 
Csharp :: NameValueCollection 
Csharp :: how to select time and date in datetimepicker in c# 
Csharp :: c# set cursor pos 
Csharp :: C# using variables inside strings 
Csharp :: unity text color 
Csharp :: how to deserialize string array in c# 
Csharp :: c# find value in datagridview 
Csharp :: set target framerate unity 
Csharp :: use slider in unity 
Csharp :: how to append something to a string in c# 
Csharp :: verify if number c# 
Csharp :: how to stop a form c# 
Csharp :: c# xml to json 
Csharp :: c# handle single quote inside string 
Csharp :: first person mouse look unity 
Csharp :: c# wpf timer 
Csharp :: dapper sql builder where 
Csharp :: c# tostring decimal 2 places 
Csharp :: unity model ripper 
Csharp :: c# color to console color 
Csharp :: c# get list object type of generic list 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =