// Update is called once per frame void Update() { #region Rotate towards Target if (target != null) { if (visionRange.CanViewTarget(target)) { targetSighted = true; searchAttempted = false; //Stop what your doing and shoot someone if (basicPatrol != null && basicPatrol.patrolModeEnabled) { basicPatrol.patrolModeEnabled = false; } if (basicSearch != null && basicSearch.searchEnabled) { basicSearch.searchEnabled = false; } if (navMeshAgent.isActiveAndEnabled) { navMeshAgent.enabled = false; if (alertSource != null) { alertSource.Play(); } } lookRotation.transform.rotation = lookRotation.GetRotationTowardsTarget(target.transform.position); #region Fire Primary Weapon if (fireProjectileCooldown.IsOffCooldown() && facing.IsFacingDirectlyAtTarget(target)) { fireProjectile.Fire(projectileOriginTransform, target.transform.position); fireProjectileCooldown.OnActionActivated(); } #endregion } //Start searching else if (!visionRange.CanViewTarget(target) && targetSighted && !searchAttempted && !basicSearch.searchEnabled) { navMeshAgent.enabled = true; basicSearch.StartSearch(target.transform); searchAttempted = true; targetSighted = false; } //Go back to patroling else if (!visionRange.CanViewTarget(target) && !basicSearch.searchEnabled && basicPatrol != null && !basicPatrol.patrolModeEnabled) { if (basicPatrol != null) { basicPatrol.patrolModeEnabled = true; navMeshAgent.enabled = true; basicPatrol.NavigateToNextWayPoint(); } } } #endregion }
// Update is called once per frame void Update() { if (target != null) { if (visionRange.CanViewTarget(target)) { if (!navMeshAgent.isActiveAndEnabled) { navMeshAgent.enabled = true; } basicFollow.FollowTarget(target, navMeshAgent); if (searchAttempted) { searchAttempted = false; } targetSighted = true; } else if (!searchAttempted && targetSighted && !basicSearch.searchEnabled) { basicSearch.StartSearch(target.transform); searchAttempted = true; targetSighted = false; } } }