//Move player towards next base if they have one //Use a list of bases to prevent them from moving directly to the final destination private void FixedUpdate() { Vector3 movementTarget = new Vector3(0, 0, 0); if (targetBase.Count > 0) { movementTarget = targetBase[0].transform.position; } //Check if they are exiting the field and then add the dugout as the target //Check how far fielders are away from the ball if (Field.CanRunnerAdvance(this)) { if (Utility.CheckEqual(movementTarget, transform.position, 0.05f)) { SetAnimationValues(Vector3.zero); enteringField = false; isAdvancing = false; if (exitingField) { targetBase.Clear(); if (Field.runners.Contains(this)) { Field.runners.Remove(this); } Destroy(transform.parent.gameObject); } else if (currentBase == 3) { player.ChangeRuns(1); GameControl.instance.ChangeTeamScore(1); exitingField = true; } if (targetBase.Count > 0) { if (targetBase[0].name.Contains("Base")) { if (GameControl.isHomeRun == false && Vector2.Distance(transform.position, Field.ball.transform.position) < 1f) { AudioControl.instance.PlayAudio("safe"); } currentBase += 1; } targetBase.Remove(targetBase[0]); } if (addedHit == false && atBat == false && exitingField == false) { player.ChangeHits(1); addedHit = true; } } else { if (!(enteringField || exitingField)) { isAdvancing = true; } MovePlayer(movementTarget); } } if (isAdvancing && (targetBase[0].name.Contains("Base") || targetBase[0].name.Contains("Plate"))) { Field.CheckIfRunnerOut(this); } }