- Home /
Need to update Material/Renderer before they can be applied?
Hi All.
I'm having a problem and not managed to find a solution scouring the net. I have one material, I create another which is the same but with some emission. When I switch the material on the renderer from the non-emissive to the emissive one, there is no change, however while it's playing in the editor and I click on the material, it then updates in game window. Is there an update function I need to run? I can't find reference to any.
Example code below:
public class UGroundMaterials : MonoBehaviour {
public Material baseMat;
private Material emissive;
public Color emission;
private MeshRenderer mr;
// Use this for initialization
void Start () {
mr = GetComponent<MeshRenderer>();
mr.material = baseMat;
emissive = new Material(Shader.Find("Standard"));
emissive.CopyPropertiesFromMaterial(baseMat);
emissive.SetColor("_EmissionColor",emission * 0.5f);
}
void Update()
{
if (Input.GetMouseButtonDown (0))
{
mr.material = emissive;
}
}
}
Thanks guys.
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Mesh collider not working correctly on voxel terrain 1 Answer
updating astar gridgraph at runtime 1 Answer