using UnityEngine;
using System.Collections;

public class EnnemyMovement : MonoBehaviour {


    public float speed=50.0f;
    public int p = 1;
    public float posInitialy;
    public float moveinterval;
    Vector3 towardPlayer;

	// Use this for initialization
	void Start ()
    {
        posInitialy = transform.position.y;
	}

    // Update is called once per frame
    void Update()
    {

        GameObject submarinePlayer = GameObject.Find("submarine(Clone)");


        if (submarinePlayer != null)
        {
            towardPlayer.y = (submarinePlayer.transform.position.y - transform.position.y);
            towardPlayer.z = -(submarinePlayer.transform.position.z - transform.position.z);

            if (tag == "Poursuite")
            {
                transform.Translate(Vector3.forward * Time.deltaTime * 1.5f*speed);
            }

            if (tag == "BigBoss")
            {
                if (transform.position.y < posInitialy - moveinterval)
                {
                    p = 1;
                }

                if (transform.position.y > posInitialy + moveinterval)
                {
                    p = -1;
                }

                transform.Translate(new Vector3(0, 1, 0) * Time.deltaTime * speed * p);

                if(submarinePlayer.transform.position.z>transform.position.z)
                {
                    transform.Translate(-Vector3.forward * Time.deltaTime *200.0f);
                }
            }

                if (tag == "Vicelard")
            {
                if (submarinePlayer.transform.position.z > transform.position.z + 150.0f)
                {
                    transform.Translate(Vector3.forward * Time.deltaTime * 1.5f * speed);
                }
            }

            if ((submarinePlayer.transform.position - transform.position).magnitude < 650.0f)
            {
                if (tag == "Horizontal")
                {
                    transform.Translate(Vector3.forward * Time.deltaTime * speed);
                }

                
                if (tag == "Vertical alterné")
                {
                    if (transform.position.y < posInitialy - moveinterval)
                    {
                        p = 1;
                    }

                    if (transform.position.y > posInitialy + moveinterval)
                    {
                        p = -1;
                    }

                    transform.Translate(new Vector3(0, 1, 0) * Time.deltaTime * speed * p);


                }

                if (tag == "Kamikaze")
                {
                    transform.Translate(towardPlayer.normalized * Time.deltaTime * 3.0f * speed);
                }
            }
        }
    }
}
