How do I modify a 'Specific' Material in my gameObject's Renderer?
I am currently trying to create a blinking light on my gameObject by modifying the object's material emission texture to switch between red and black via code. So good, so far. Everything works apart from one thing. My object has two materials. One is for a glass component present on the object. The other is the mechanical components (Including the light). The issue I have is that my script is trying to switch the emission values on my glass and, for some reason, isn't touching my other material. I expect there is a way I can specify exactly which material to manipulate. But with much searching, I have failed. I can't drag and drop the material into my "public Material x" either. Any tips?
using UnityEngine;
using System.Collections;
public class Blinking_Light_Script : MonoBehaviour {
public MeshRenderer Emission;
public Texture Emission_Texture;
public int Emission_Timer;
public int Emission_Frequency = 20;
public bool Emission_On;
// Use this for initialization
void Start ()
{
//Get Reference
Emission = GetComponent<MeshRenderer> ();
}
// Update is called once per frame
void Update ()
{
//Deduct From Timer
if (Emission_Timer > 0) {Emission_Timer--;}
// Switch Texture and Reset Timer
if ((Emission_Timer <= 0) && (Emission_On))
{
Emission_Timer = Emission_Frequency;
Emission_On = false;
Emission.material.SetColor ("_EmissionColor", Color.red);
}
if ((Emission_Timer <= 0) && (!Emission_On))
{
Emission_Timer = Emission_Frequency;
Emission_On = true;
Emission.material.SetColor ("_EmissionColor", Color.black);
}
}
}
Never $$anonymous$$d. Stupid Question. Just realized I was using "public $$anonymous$$eshRenderer" ins$$anonymous$$d of "public $$anonymous$$aterial". I can drag and drop the $$anonymous$$aterial straight into that. $$anonymous$$y bad. It's usually something really stupid that I should have noticed before.