using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class GenerationController : MonoBehaviour { internal GameObject[] waypoints; private int waypointIndex = 1; private Rigidbody2D rb; // Start is called before the first frame update private void Start() { rb = GetComponent(); } // Update is called once per frame void Update() { } private void FixedUpdate() { if (waypointIndex < waypoints.Length) { var target = waypoints[waypointIndex].transform.position; var direction = target - transform.position; var f = transform.position + direction.normalized * 0.1f; rb.MovePosition(f); } else if (waypointIndex >= waypoints.Length) { Destroy(gameObject); } } private void OnTriggerEnter2D(Collider2D col) { if (col.gameObject == waypoints[waypointIndex]) { waypointIndex++; } } public void setWaypoints(GameObject[] waypointsIn) { waypoints = waypointsIn; } }