using UnityEngine;
using System.Collections;

public class StageEndReached : MonoBehaviour {
	public Transform StandPoint;
	private bool completed = false;
	public GameObject audioObject;


	void Update()
	{
		if (audioObject.activeSelf) {
			if(!audioObject.GetComponent<AudioSource>().isPlaying)
			{
				Application.LoadLevel ("title");
			}
		}
	}

	void OnTriggerEnter2D(Collider2D collider)
	{
		if (!completed) {
			if (collider.gameObject.layer == 9) {
				BirdController.instance.transform.position = StandPoint.position;
				BirdController.instance.MoveEnabled = false;
				BirdController.instance.rigidbody2D.gravityScale = 0;
				GameManager.instance.CurrentStage.CompleteStage();
				audioObject.SetActive(true);
				completed = true;
			}
		}
	}
}
