using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ReachTurn : MonoBehaviour
{
    void Update()
    {
        float minz = GetComponent<Piece>().player * 12;
        float maxz = GetComponent<Piece>().player * 17;
        if (minz > maxz)
        {
            float temp = minz; minz = maxz; maxz = temp;
        }
        if (transform.position.z > minz && transform.position.z < maxz && GetComponent<Rigidbody>().velocity.magnitude < 0.1f)
        {
            string obje = GetComponent<Piece>().player == 1 ? "WhiteQueen" : "BlackQueen";
            GameObject q = GameObject.Instantiate(Resources.Load<GameObject>("Pieces/" + obje));
            q.transform.position = transform.position;
            q.transform.rotation = transform.rotation;
            q.GetComponent<Rigidbody>().velocity = GetComponent<Rigidbody>().velocity;
            Camera.main.GetComponent<ChessScript>().PromotionClip(GetComponent<Piece>().player);
            Destroy(gameObject);
        }
    }
}
