protected void UpdateHuntForTarget() { if (IsColliderInSight(target)) { // Target is in sight again! if (!player.hullAlarmEnabled) { AudioManager.instance.Play(AudioBank.MUS_TENSION, this.gameObject); } AudioManager.instance.Play(AudioBank.SFX_ENEMY_TALK, this.gameObject); currentPath = null; targetPositionAtLastPathFinding = null; SetState(States.AttackTarget); } else if (waypoints != null) { if (targetPositionAtLastPathFinding == null || waypoints.connectionToggledLastFrame || Vector3.Distance(targetPositionAtLastPathFinding.Value, target.transform.position) > refreshPathToTargetWhenHeMovesBy) { targetPositionAtLastPathFinding = target.transform.position; var enemyWaypoint = FindNearestReachableWaypoint(transform.position); var playerWaypoint = FindNearestReachableWaypoint(target.transform.position); currentPath = waypoints.FindPath(enemyWaypoint, playerWaypoint); currentPathIndex = 0; } if (currentPath != null && currentPath.success) { if (Vector3.Distance(transform.position, currentPath.path[currentPathIndex].position) < distanceToReachPathNode) { if (currentPathIndex < currentPath.path.Length - 1) { currentPathIndex++; } } for (var i = currentPath.path.Length - 1; i > currentPathIndex; i--) { if (IsPositionDirectlyReachable(currentPath.path[i].position)) { currentPathIndex = i; } } pilotTargetPosition = currentPath.path[currentPathIndex].position; } else { //AudioManager.instance.Play(AudioBank.MUS_NONE, this.gameObject); currentPath = null; currentPathIndex = 0; pilotTargetPosition = null; } } }
protected void UpdateHuntForTarget() { if (IsColliderInSight(target)) { // Target is in sight again! if(!player.hullAlarmEnabled) AudioManager.instance.Play(AudioBank.MUS_TENSION, this.gameObject); AudioManager.instance.Play(AudioBank.SFX_ENEMY_TALK, this.gameObject); currentPath = null; targetPositionAtLastPathFinding = null; SetState(States.AttackTarget); } else if (waypoints != null) { if (targetPositionAtLastPathFinding == null || waypoints.connectionToggledLastFrame || Vector3.Distance(targetPositionAtLastPathFinding.Value, target.transform.position) > refreshPathToTargetWhenHeMovesBy) { targetPositionAtLastPathFinding = target.transform.position; var enemyWaypoint = FindNearestReachableWaypoint(transform.position); var playerWaypoint = FindNearestReachableWaypoint(target.transform.position); currentPath = waypoints.FindPath(enemyWaypoint, playerWaypoint); currentPathIndex = 0; } if (currentPath != null && currentPath.success) { if (Vector3.Distance(transform.position, currentPath.path[currentPathIndex].position) < distanceToReachPathNode) { if (currentPathIndex < currentPath.path.Length - 1) { currentPathIndex++; } } for (var i = currentPath.path.Length - 1; i > currentPathIndex; i--) { if (IsPositionDirectlyReachable(currentPath.path[i].position)) { currentPathIndex = i; } } pilotTargetPosition = currentPath.path[currentPathIndex].position; } else { //AudioManager.instance.Play(AudioBank.MUS_NONE, this.gameObject); currentPath = null; currentPathIndex = 0; pilotTargetPosition = null; } } }