AsteroidGame/Assets/Entities/Enemies/Scripts/EnemyMovement.cs

63 lines
1.4 KiB
C#

using System.Collections;
using AsteroidGame.Handlers;
using UnityEngine;
namespace AsteroidGame.Entities.Enemies
{
public class EnemyMovement : MonoBehaviour
{
[Header("Parameters")]
[SerializeField] [Range(0f, 5f)] float speed = 1f;
[SerializeField] int damage = 1;
[SerializeField] EnemyHandler enemyHandler;
[SerializeField] ScoreHandler scoreHandler;
Vector3 startPosition;
Vector3 endPosition;
float travelPercent = 0f;
private IEnumerator followPath;
void Awake()
{
enemyHandler = FindObjectOfType<EnemyHandler>();
scoreHandler = FindObjectOfType<ScoreHandler>();
}
void OnEnable()
{
enemyHandler.AddEnemyToAllEnemies(gameObject);
}
void RecalculatePath()
{
if (followPath != null)
{
//Debug.Log("Stopping Coroutine");
StopCoroutine(followPath);
}
}
void HandleReachedEndOfPath()
{
scoreHandler.ModifyHealth(-damage);
scoreHandler.ModifyWealth(-100);
enemyHandler.RemoveEnemy(gameObject);
//Destroy(gameObject);
gameObject.SetActive(false);
}
private Vector3 GetVector3(Vector2Int _coord)
{
return new Vector3((float)_coord.x, 0f, (float)_coord.y) * 10f;
}
}
}