public object TargetMoreNear() { float nearestTargetDistance = Mathf.Infinity; GameObject currentMinDist = null; foreach (GameObject player in GameObject.FindGameObjectsWithTag(Tags.player)) { if (!player.GetComponent <PlayerController>().downed) { PathRequestManager.RequestPath(new PathRequest(transform.position, player.transform.position, delegate(Vector3[] waypoints, bool pathSuccessful) { if (pathSuccessful) { float tmpDistance = PathRequestManager.DistanceFromTarget(waypoints, transform.position, targetIndex = 0); if (tmpDistance < nearestTargetDistance) { nearestTargetDistance = tmpDistance; currentMinDist = player; target = currentMinDist.transform; targetFound = true; } } })); } } if (target != null) { targetFound = true; } /*anim.SetBool("TargetDead", false); * RpcSetAnimBool("TargetDead", false);*/ return(null); }
IEnumerator FollowPath() { following = true; float speedPercent = 1; Vector3 currentWaypoint = pathToTarget[0]; while (true) { if (transform.position == currentWaypoint) { targetIndex++; if (targetIndex >= pathToTarget.Length - attackRange && InLineOfSight()) { targetIndex = 0; pathToTarget = new Vector3[0]; anim.SetBool("TargetInRange", true); RpcSetAnimBool("TargetInRange", true); following = false; yield break; } if ((PathRequestManager.DistanceFromTarget(pathToTarget, transform.position, targetIndex) < attackRange) && InLineOfSight()) { targetIndex = 0; pathToTarget = new Vector3[0]; anim.SetBool("TargetInRange", true); RpcSetAnimBool("TargetInRange", true); following = false; yield break; } if (targetIndex < pathToTarget.Length) { currentWaypoint = pathToTarget[targetIndex]; } if (targetIndex >= slowDownIndex && slowDownDistance > 0) { speedPercent = Mathf.Clamp01(PathRequestManager.DistanceFromTarget(pathToTarget, transform.position, targetIndex) / slowDownDistance); if (speedPercent < 0.01f) { anim.SetBool("TargetInRange", true); RpcSetAnimBool("TargetInRange", true); following = false; yield break; } } } if (canMove) { RpcSetDirection(); if (wasInRangeWhenFeared && target != null) { transform.position = Vector3.MoveTowards(transform.position, transform.position + (target.position - transform.position), -0.25f * speed * speedPercent * Time.deltaTime); } else { transform.position = Vector3.MoveTowards(transform.position, currentWaypoint, (isFearead ? (-0.25f * speed) : speed) * speedPercent * Time.deltaTime); } } yield return(null); } }