// Update is called once per frame void FixedUpdate() { agent.SetDestination(player.position); Ray ray = new Ray(transform.position, player.GetComponent <Movement>().GetMiddle() - transform.position); Debug.DrawRay(transform.position, player.GetComponent <Movement>().GetMiddle() - transform.position, Color.red, Time.fixedDeltaTime); RaycastHit hit; Physics.Raycast(ray, out hit, VisionDistance, DetectableLayers); if (hit.collider != null) { if (hit.transform.name == "Player") { AttachedGun.Shoot(); } } }
void ManageTarget() { bool enemyInSight = false; if (target == null) { ai.agent.isStopped = false; return; } ai.agent.isStopped = true; // We re evaluate the quality of our target if (!isEnemyTooFar(target.position)) { if (isInConeOfSight(target.position)) { enemyInSight = LineofSightClear(target.position); } } // If our target is not good anymore if (!enemyInSight) { target = null; return; } // else we adjust our rotation and our gun's CustomPlayerLookAt(); gun.CustomLookAt(target.position); // if we can shoot if (gun.canShoot) { gun.Shoot(); } }