MAAC3601-TD-Game/Assets/Scripts/GenerationController.cs

40 lines
1011 B
C#
Raw Normal View History

2023-02-13 19:38:57 -04:00
using System;
2023-02-13 17:50:51 -04:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2023-02-13 19:38:57 -04:00
public class GenerationController : MonoBehaviour {
2023-02-16 19:07:21 -04:00
internal GameObject[] waypoints;
private int waypointIndex = 1;
private Rigidbody2D rb;
// Start is called before the first frame update
private void Start() {
rb = GetComponent<Rigidbody2D>();
}
// 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;
}
}