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

public class Frontline : MonoBehaviour
{
    //public GameObject origin;
    float speed = 5;
    Rigidbody2D rb;

    Transform target;
    // Use this for initialization
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        rb.MovePosition(transform.position + (Vector3.left * speed * Time.deltaTime));
    }

    private void OnDestroy()
    {
        //origin.GetComponent<EnemyControl>().enemies.Remove(this.gameObject);
    }

    public void SetTarget(Transform _T)
    {
        target = _T;
    }
    public void SetSpeed(float _S)
    {
        speed = _S;
    }
    public Vector3 GetDirection(Vector3 _A, Vector3 _B)
    {
        Vector3 dist = _A - _B;
        Vector3 dir = new Vector3(0, 0, 0);
        if (dist.x >= dist.y && dist.x >= dist.z)
        {
            dir = new Vector3(dist.x / dist.x, dist.y / dist.x, dist.z / dist.x);
        }
        else if (dist.y >= dist.x && dist.y >= dist.z)
        {
            dir = new Vector3(dist.x / dist.y, dist.y / dist.y, dist.z / dist.y);
        }
        else if (dist.z >= dist.x && dist.z >= dist.y)
        {
            dir = new Vector3(dist.x / dist.z, dist.y / dist.z, dist.z / dist.z);
        }
        return dir;
    }
    private void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject.tag == "Player" && col.gameObject.GetComponent<HealthScript>() != null)
        {
            col.gameObject.GetComponent<HealthScript>().TakeDamage(100);
            Destroy(this.gameObject);
        }
    }
}
