using UnityEngine;
using System.Collections;

public class MainMenu : MonoBehaviour {
	private GameObject splash;
	private GameObject howToPlay;
	private GameObject buttonPosition;
	
	public Texture startButton;
	public Texture playButton;
	
	public void Start () {
		splash = GameObject.Find("Splash");
		howToPlay = GameObject.Find("HowToPlay");
		buttonPosition = GameObject.Find("ButtonPosition");
		
		splash.SetActive(true);
		howToPlay.SetActive(false);
	}
	
	public void OnGUI() {
		int buttonW = 483 / 2;
		int buttonH = 233 / 2;
		
		Vector3 pos = Camera.main.WorldToScreenPoint(buttonPosition.transform.position);
		int buttonX = (int)pos.x - buttonW/2;
		int buttonY = (int)pos.y - buttonH/2 + 350;
		
		if (splash.activeInHierarchy) {
			if (GUI.Button(new Rect(buttonX, buttonY, buttonW, buttonH), startButton, GUIStyle.none)) {
				splash.SetActive(false);
				howToPlay.SetActive(true);
			}
		}
		else {
			if (GUI.Button(new Rect(buttonX, buttonY, buttonW, buttonH), playButton, GUIStyle.none)) {
				Application.LoadLevel("Game");
			}
		}
		
		if (Input.GetKeyUp("escape")) Application.Quit();
	}
	
	public void Update () {
		
	}
}
