using UnityEngine;
using System.Collections;

public class EnemyJet : EnemyController
{
    public GameObject ALART;

    private GameObject m_alart;

    private Vector3 vAlartPos;

    protected override void Start()
    {
        base.Start();
        m_alart = Instantiate(ALART);

        vAlartPos = Vector3.zero;
    }

	// Update is called once per frame
	public override void Update () 
    {
        base.Update();

        //update alart status
        if( transform.position.x > 20 )
        {
            //find alart pos if we haven't already
            if (vAlartPos == Vector3.zero)
            {
                float xFromCamera = 2.0f;
                vAlartPos = transform.position;
                vAlartPos.x = 13.0f;

                while (xFromCamera > 0.90f)
                {
                    vAlartPos.x -= 0.5f;
                    Vector3 camPoint = Camera.main.WorldToViewportPoint(vAlartPos);
                    xFromCamera = camPoint.x;
                }
            }


            //draw alart!
            if (m_alart != null)
            {
                vAlartPos.y = transform.position.y;
                m_alart.transform.position = vAlartPos;
            }
        }
        else
        {
            Destroy(m_alart);
            m_alart = null;
        }

        if( transform.position.x < -10)
            Destroy(gameObject);
	}
}
