using UnityEngine;
using System.Collections;

public class Credits : MonoBehaviour {
	private float offset;
	public float speed = 29.0f;
	public GUIStyle style;
	public Rect viewArea;
	[SerializeField] private string nextScene;
	[SerializeField] private bool startCheck;
	float timeTaken;

	private void Start()
	{
		if (this.viewArea.width == 0.0f)
		{
			this.viewArea = new Rect(0.0f, 0.0f, Screen.width, Screen.height);
		}
		this.offset = this.viewArea.height;
	}
	
	private void Update()
	{
		timeTaken += 1 * Time.deltaTime;
		if (timeTaken > 24)
			finish ();
		this.offset -= Time.deltaTime * this.speed;
		if ( Input.GetKeyDown(KeyCode.Space) || Input.GetButton("Fire1"))
			finish ();
	}

	private void finish()
	{
		if (nextScene.Length > 0)
			Application.LoadLevel(nextScene);
		else
			Application.Quit();
	}
	
	private void OnGUI()
	{
		GUI.BeginGroup(this.viewArea);
		GUI.color = Color.yellow;
		var position = new Rect(0, this.offset, this.viewArea.width, this.viewArea.height);
		var text = getText();
		
		GUI.Label(position, text, this.style);
		
		GUI.EndGroup();
	}
	public string getText()
	{
		string text;
		if (startCheck)
			text = @"Congratulations! You've destroyed the evil
 robot menace, the galaxy is free at last from 
 their rule.

 Lead Designer:
 Nobody, this was really badly planned
 
 Character Assets:
 Monica Dunne
 Pritika Sachdev

 Programming:
 Milton Plotkin
 Owen Thomas
 Tim Patullock

 Audio:
 Gerrard Jenner

 Level Design
 Everyone


 ...



 Except... You were on the wrong ship, and Command
 requires that you get back to your craft and repair
 some of the damage you've caused on your rampage...

 Best of luck!


 ...



 DAMNIT. ";
		else
			text = @"Great! You've made it back to your ship
Now to go save the world.";
		
		return text;
	}
}



