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

40 lines
1.2 KiB
C#
Raw Permalink 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;
2018-04-22 16:40:31 +00:00
private SongData songData;
2018-04-22 12:07:55 +00:00
void Start () {
gameStatus = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameStatus>();
2018-04-22 16:40:31 +00:00
songData = GameObject.FindGameObjectWithTag("GameController").GetComponent<SongData>();
2018-04-22 12:07:55 +00:00
}
void Update () {
2018-04-23 19:05:37 +00:00
Vector3 newPosition = Vector3.MoveTowards(transform.position, path[nextStop], speed * Mathf.Pow(Mathf.Cos(songData.songTime * Mathf.PI * songData.bpm / 60), 10) * Time.deltaTime);
2018-04-22 16:40:31 +00:00
if ((newPosition - transform.position).x < 0)
{
transform.localScale = new Vector3(-1, 1, 1);
}
else if ((newPosition - transform.position).x > 0)
{
transform.localScale = new Vector3(1, 1, 1);
}
if (Vector3.Distance(transform.position, path[nextStop]) == 0)
2018-04-22 12:07:55 +00:00
{
nextStop++;
if (nextStop >= path.Length)
{
gameStatus.EnemyFinishedPath(gameObject);
}
}
transform.position = newPosition;
}
}