using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public class SpawnManager : MonoBehaviour {

	public GameObject UpPrefab;
	public GameObject DownPrefab;
	public GameObject Poserinstance;

	private GameObject current;
	private GameObject currentNext;

	// Use this for initialization
	void Start () {


	}


	public void Spawn(bool rot)
	{
		GameObject tmpPrefab;
		if (!rot) {
			tmpPrefab = UpPrefab;
		} else {
			tmpPrefab = DownPrefab;
		}

		current=Instantiate (tmpPrefab,transform.position,Quaternion.identity);

		Vector3 desiredPos = new Vector3 (Poserinstance.transform.position.x,transform.position.y,transform.position.z);
		current.transform.DOMove (desiredPos, GameManager.instance.CurrentGameSpeed).OnComplete (killMe);
	}



	public void Next(bool rot)
	{
		GameObject tmpPrefab;
		if (!rot) {
			tmpPrefab = UpPrefab;
		} else {
			tmpPrefab = DownPrefab;
		}

		currentNext=Instantiate (tmpPrefab,transform.position,Quaternion.identity);

		//Vector3 desiredPos = new Vector3 (transform.position.x,transform.position.y,transform.position.z);
	//	currentNext.transform.position = desiredPos;
		Vector3 desiredPos = new Vector3 (Poserinstance.transform.position.x,transform.position.y,transform.position.z);
		currentNext.transform.DOMove (desiredPos, GameManager.instance.CurrentGameSpeed).SetDelay(GameManager.instance.CurrentGameSpeed).OnComplete (killNext);

	}
		


	void killMe()
	{
		Destroy (current);
	}



	void killNext()
	{
		Destroy (currentNext);
	}
}
