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

48 lines
1.1 KiB
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 {
public GameObject PathGameObject;
private Rigidbody2D rb;
int pathIndex = 0;
bool moving = false;
private GameObject pathPointer;
2023-02-13 17:50:51 -04:00
// Start is called before the first frame update
void Start()
{
2023-02-13 19:38:57 -04:00
rb = GetComponent<Rigidbody2D>();
PathGameObject = GameObject.Find("Path");
2023-02-13 17:50:51 -04:00
}
// Update is called once per frame
void Update()
{
}
2023-02-13 19:38:57 -04:00
private void FixedUpdate() {
pathPointer = PathGameObject.GetComponent<PathingController>().waypointList[pathIndex] as GameObject;
if (!moving) {
Vector2 force = new Vector2(pathPointer.transform.position.x, pathPointer.transform.position.y);
rb.AddForce(force);
moving = true;
}
}
private void OnTriggerEnter2D(Collider2D col) {
if (col.gameObject == pathPointer) {
moving = false;
pathIndex++;
}
}
2023-02-13 17:50:51 -04:00
}