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

public class EnemyManager_old : MonoBehaviour {
	public GameObject player;
	public GameObject enemy;
	public Transform[] points;
	public AudioClip[] footstepClips;
	public Transform start;
	public bool alert = false;

	private AudioSource footsteps;

	public float initSpeed = 15.0f;
	private int destPoints = 0;
	private float delay = 2.0f;
	private float timer = 0.0f;
	private float speedInc = 10.0f;
	private UnityEngine.AI.NavMeshAgent agent;

	// Use this for initialization
	void Start () {
		agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
		GotoNextPoint();
		//footsteps = GetComponent<AudioSource>();
		//footsteps.clip = footstepClips[0];

	}
	//Waypoint Patrol for Enemy
	void GotoNextPoint(){
		if(points.Length == 0) return;
		agent.destination = points[destPoints].position;
		destPoints = (destPoints + 1) % points.Length;
	}


	void LookAround(){
		Vector3 fwd = transform.TransformDirection(Vector3.forward);
		if(Physics.Raycast(enemy.transform.position, fwd, 10)){

		}
	}

	void repeatAudio(){

	}

	void ChasePlayer(){
		alert = false;
		timer = 0;
	}


	// Update is called once per frame
	void Update () {
		if(!alert){
			if(agent.remainingDistance < 0.5f){
				GotoNextPoint();
				agent.speed = initSpeed;
			}else if(enemy.name == "Enemy-Patrol"){
				agent.destination = points[destPoints].position;
			}
		} else{
			timer += Time.deltaTime;
			if(timer > delay){
				ChasePlayer();
			}

		}

		if(Input.GetKeyUp(KeyCode.Space)){
			agent.destination = player.transform.position;
			agent.speed += speedInc;
			alert = true;
			timer = 0;
		}
	}

	void OnTriggerEnter(Collider other){
		if(other.name == "killZone"){
			player.transform.position = start.position;

		}else if(other.name == "chaseZone"){
			
		}else if(other.name == "presenceZone"){
			alert = true;
		}
	}

	void OnTriggerLeave(Collider other){
		if(other.name == "chaseZone"){

		}else if(other.name == "presenceZone"){
			alert = false;
			//footsteps.Pause();

		}
	}

}
