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

public class Patient : MonoBehaviour {

public MonoBehaviour stopsBeingAPatient;
public float distanceFromPlayer;
public GameObject Player;
public float patientenRunningSpeed;
public float patientenRotationSpeed;
public bool fear;
public Rigidbody rb;



	// Use this for initialization
	void Start () {
		rb = gameObject.GetComponent<Rigidbody>();
    GameManager.instance.patienten += 1;
		patientenRotationSpeed = 15;
		patientenRunningSpeed = 4;
		Player = GameObject.Find("Player");


	}

	// Update is called once per frame
	void Update () {
		distanceFromPlayer = Vector3.Distance (Player.transform.position, this.gameObject.transform.position);

		if (fear == true && distanceFromPlayer < 7)
		{
			transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(Player.transform.position  - transform.position), patientenRotationSpeed * Time.deltaTime);
			transform.position += transform.forward * (patientenRunningSpeed* -1) * Time.deltaTime;


		}
		if (GameManager.instance.infectionPower >= 10)
		{
			fear = true;
		}



		}
    void OnCollisionEnter(Collision col)
    {
        if (col.gameObject.tag == "Player")
        {
            // auf GameManager zugreifen, Wert für Beacon verringern
            GameManager.instance.infectionPower += 1;
						rb.AddForce(-transform.forward * 500);
            //Zerstört das Script. Patienten werden zu Infizierten
            GameManager.instance.patienten -= 1;
            Destroy (GetComponent<Patient>());

    }
	}
}
