UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"2D character jumping on waypoints"
public class JumpOnWaypoints : MonoBehaviour { [SerializeField] private GameObject[] wayPoitns; private IEnumerator goCoroutine; private float timeIntervalBetweenSteps; private int stepCounter; // Start is called before the first frame update void Start() { timeIntervalBetweenSteps = 0.5f; stepCounter = 0; goCoroutine = Go(); StartCoroutine(goCoroutine); } private IEnumerator Go() { while (true) { transform.position = wayPoitns[stepCounter].transform.position; stepCounter = 1; if (stepCounter > wayPoitns.Length - 1) { stepCounter = 0; } yield return new WaitForSeconds(timeIntervalBetweenSteps); } } }