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

public class Arzt : MonoBehaviour {

    //Arzt Stats
    public float curarztHealth;
    public float arztPower;

    // Movement
    public GameObject Player;
    public float arztMovementSpeed;
    public float aggroRange = 10;
    public bool inReach;
    public float arztRotationspeed = 2;

    public Rigidbody rb;

    //



    void Start()
    {

        curarztHealth = 3;
        Player = GameObject.Find("Player");
        arztMovementSpeed = 1;
        rb = Player.GetComponent<Rigidbody>();
    }

    void Update()
    {
        //transform.LookAt(Player);

        if (Vector3.Distance(transform.position, Player.transform.position) <= aggroRange)
        {
            inReach = true;
        }
        else
        {
            inReach = false;
        }

        if (inReach == true)
        {
            //rotation
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(Player.transform.position - transform.position), arztRotationspeed * Time.deltaTime);
            //movement
            if (arztMovementSpeed < 6)
            {
              arztMovementSpeed = arztMovementSpeed + 0.02f;
            } else {
              arztMovementSpeed = 6;
            }

            transform.position += transform.forward * arztMovementSpeed * Time.deltaTime;

        }
        else
        {
            arztMovementSpeed = 1;
        }

        if (curarztHealth <= 0)
        {
            gameObject.SetActive(false);
        }
    }
    void OnCollisionStay(Collision col)
    {
        if (col.gameObject.tag == "Player")
        {
            GameManager.instance.infectionPower -= 5 * Time.deltaTime;
            rb.AddForce(transform.forward * 5000);
        }
    }
        void OnCollisionEnter(Collision coli)
        {
            if (coli.gameObject.tag == "Infected")
            {
                curarztHealth -= 1;
                arztMovementSpeed = arztMovementSpeed - 1.5f;
            }
        }
    }
