void CheckForBlockzilla() { if (currentTarget != null) { return; } if (EventHandler.instance.CheckForBlockzillaEvent()) { moveIdle = false; currentTarget = FindClosestBlockzilla(GameObject.FindObjectsOfType <BlockZillaBehaviour> (), currentTarget); FindDirectionToTarget(currentTarget.transform.localPosition); CurrentMoveSpeed = RunningSpeed; } else { moveIdle = true; GetNewDirection(); currentTarget = null; CurrentMoveSpeed = WalkingSpeed; } }
public BlockZillaBehaviour FindClosestBlockzilla(BlockZillaBehaviour[] targets, BlockZillaBehaviour currentTarget) { Vector3 currentPos = gameObject.transform.position; BlockZillaBehaviour tMin = null; float minDist = Mathf.Infinity; foreach (var target in targets) { if (currentTarget == target) { continue; } float dist = Vector3.Distance(target.transform.position, currentPos); if (dist < minDist) { tMin = target; minDist = dist; } } return(tMin); }