using UnityEngine;
using System.Collections;
public class Detection : MonoBehaviour
{
public float fieldOfView = 80.0f;
public bool IsDetected;
private bool answer;
private GameObject player;
private SphereCollider col;
void Awake()
{
player = GameObject.FindGameObjectWithTag("Player");
col = GetComponent<SphereCollider>();
}
void Update()
{
//Every Frame
}
void OnTriggerStay(Collider other)
{
if(other.gameObject == player)
{
IsDetected = false;
Vector3 direction = other.transform.position - transform.position;
float angle = Vector3.Angle(direction, transform.forward);
Debug.DrawRay(transform.position+transform.up/4, direction, Color.green);
Debug.Log(angle);
if(angle < fieldOfView)
{
RaycastHit hit;
if (Physics.Raycast(transform.position + transform.up/4,direction, out hit, col.radius))
{
if(hit.collider.gameObject == player)
{
IsDetected = true;
}
}
}
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject == player)
{
IsDetected = false;
}
}
}