using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemyVision : MonoBehaviour { private Enemy enemyScript; public GameObject playerCenter; public float range = 5.2f; public float fieldOfView = 45f; private float distanceToPlayer; private float angleToPlayer; private Vector3 targetDirection; private RaycastHit whatHasBeenHit; private void Start() { enemyScript = GetComponent<Enemy>(); if (playerCenter == null) { playerCenter = GameObject.FindWithTag("Player"); } } void Update() { targetDirection = playerCenter.transform.position - this.transform.position; // angleToPlayer = Vector3.Angle(targetDirection, transform.forward); // distanceToPlayer = Vector3.Distance(playerCenter.transform.position, this.transform.position); // Debug.DrawRay(this.transform.position, transform.forward * range, Color.green, 1, true); // // if (angleToPlayer < fieldOfView && distanceToPlayer < range ) { // // if (Physics.Raycast(this.transform.position, targetDirection, out whatHasBeenHit, range)) { // if (whatHasBeenHit.collider.gameObject.tag == "Player") { Debug.DrawRay(transform.position, targetDirection, Color.red, 1, true); Debug.Log("seen player"); // enemyScript.state = 2; } else { // enemyScript.state = 1; } } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)