using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GenerationController : MonoBehaviour {

    public GameObject PathGameObject;
    private Rigidbody2D rb;

    int pathIndex = 0;

    bool moving = false;

    private GameObject pathPointer;
    
    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        PathGameObject = GameObject.Find("Path");
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    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++;
        }
    }
}
