using System; using System.Collections; using UnityEngine; using Random = UnityEngine.Random; public class Enemy : Entity { public SpriteRenderer sprite; private float currentState = 1; public float colorChangeSpeed; [Header("Movement")] private float currentMovement; public float moveSpeed; public float moveSpeedDelta; private void Start() { moveSpeed += Random.Range(-moveSpeedDelta, moveSpeedDelta); } private void Update() { if (!isStalled) { foreach (Ability ability in abilities) { ability.direction = WaveManager.instance.GetRandomPlayerPoint(); bool success = ability.TryAbility(); if (!success && ability.currentCooldown <= 0.5f && currentState >= 1f) { currentState = 0f; StartCoroutine(ImminentAttackAnim()); } } } } protected override void OnDeath() { base.OnDeath(); Destroy(gameObject); WaveManager.instance.enemiesInPlay.Remove(this); WaveManager.instance.UpdateKills(); } private IEnumerator ImminentAttackAnim() { while (currentState < 1) { currentState += Time.deltaTime * colorChangeSpeed; sprite.color = Color.Lerp(Color.red, Color.white, currentState); yield return null; } } public IEnumerator MoveToPosition(Vector3 moveDirection) { while (currentMovement < 1) { currentMovement += Time.deltaTime * moveSpeed; if (currentMovement >= 1) { isStalled = false; } transform.position = Vector3.Lerp(WaveManager.instance.enemySpawnPoint.position, moveDirection, currentMovement); yield return null; } } }