using UnityEngine;
using System.Collections;

public class SwitchColorChange : MonoBehaviour
{
    public Switch button;
    public Color colorDefault;
    public Color colorActivated;
    public Material material;
    public Renderer renderTarget;
    public int materialSlot;

    private void Start()
    {
        renderTarget.materials[materialSlot] = material;
        renderTarget.materials[materialSlot].color = button.IsActivated ? colorActivated : colorDefault;
        button.Triggered += OnButtonTriggered;
    }

    private void OnButtonTriggered(object sender, bool newState)
    {
        renderTarget.materials[materialSlot].color = newState ? colorActivated : colorDefault;
    }
}
