using UnityEngine;
using System.Collections;

public class Respawner : MonoBehaviour
{
	public Transform player;

	public iTween.EaseType easeFade;
	public float fadeTime;

	public static Respawner instance;

	private void Awake()
	{
		instance = this;
	}

	private void Start()
	{
		Respawn();
	}

	[ContextMenu("Respawn")]
	public void Respawn()
	{
		if(GameManager.instance.lives < 0) return;

		player.transform.position = transform.position;
		player.GetComponent<Rigidbody2D>().velocity = Vector2.one;

		player.GetComponentInChildren<Animator>().SetBool("Die", false);
	}

	public void SetAlpha(GameObject gameObject, float value)
	{
		foreach(var renderer in gameObject.GetComponentsInChildren<SpriteRenderer>())
		{
			float r = renderer.color.r;
			float g = renderer.color.g;
			float b = renderer.color.b;

			renderer.color = new Color(r, g, b, value);
		}
	}
}