Change Material Unity C# Code Example


Example 1: c# change material in code


currentObject.GetComponent<Renderer>().material = materialToAssign;

Example 2: how to set material c unity


Renderer rend = GetComponent<Renderer>();
if (rend != null){
rend.material = newMaterialRef;
}

Example 3: how to change material in script unity


public Material Material1;
//in the editor this is what you would set as the object you wan't to change
public Renderer Object;

void Start()
{
Object.material = Material1;
}

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable