1
Fork 0
mirror of https://github.com/Steffo99/beat-td.git synced 2024-11-22 23:34:19 +00:00
beat-td/Assets/Scripts/EnemyMovement.cs

30 lines
791 B
C#
Raw Normal View History

2018-04-22 12:07:55 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMovement : MonoBehaviour {
public Vector3[] path;
public float speed = 1;
private int nextStop = 0;
private GameStatus gameStatus;
void Start () {
gameStatus = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameStatus>();
}
void Update () {
Vector3 newPosition = Vector3.MoveTowards(transform.position, path[nextStop], speed * Time.deltaTime);
if (Vector3.Distance(transform.position, newPosition) == 0)
{
nextStop++;
if (nextStop >= path.Length)
{
gameStatus.EnemyFinishedPath(gameObject);
}
}
transform.position = newPosition;
}
}