using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class OnOffButton : MonoBehaviour {
	public Color onColor;
	public Color onHoverColor;
	public Color onClickedColor;
	public Color offColor;
	public Color offHoverColor;
	public Color offClickedColor;
	public bool state;
	public OnOffGroup group;
	public GameObject tab;

	void Start () {
		setState(state);
		if (group != null) {
			group.addButton(this);
		}
	}

	public void click() {
		setState(!state);
		if (group != null) {
			group.updateStates(this);
		}
	}

	public void setState(bool newState) {
		state = newState;

		ColorBlock block = gameObject.GetComponent<Button>().colors;
		block.normalColor = state ? onColor : offColor;
		block.highlightedColor = state ? onHoverColor : offHoverColor;
		block.pressedColor = state ? onClickedColor : offClickedColor;
		gameObject.GetComponent<Button>().colors = block;
	}
}
