using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemyBehavior : MonoBehaviour { public float speed = 0; public static int enemyAmount; private bool alive = true; // Start is called before the first frame update void Awake() { enemyAmount++; } private void Start() { //StartCoroutine(walk(Random.Range(1, 3))); //grid base walk. Deprecated } // Update is called once per frame void Update() { if(alive) transform.position += Vector3.Normalize(GameManager.Instance.player.GetComponent().getClosestPlayer(transform.position).transform.position - transform.position) * speed * Time.deltaTime; } public void Kill() { alive = false; GameManager.Instance.enemies.Remove(gameObject); if (GameManager.Instance.enemies.Count == 0) { GameManager.Instance.nextRound(); } //disable enemy capabilitiyes GetComponent().enabled = false; //prevent player kill GetComponent().enabled = false; //prevent rotation GetComponentInChildren().SetBool("Die", true); //fire anim LeanTween.moveY(gameObject, transform.position.y + .5f, 0.1f).setEaseOutQuint(); LeanTween.moveY(gameObject, transform.position.y - .5f, 0.35f).setEaseInQuint().setDelay(0.1f); LeanTween.moveY(gameObject, transform.position.y - 1, 1.1f).setEaseInQuint().setDelay(0.45f); //add score GameManager.Instance.ScoreSys.AddScore(MyVars.enemyKillScore, true); StartCoroutine(DestroyGameObject(1.5f)); } IEnumerator DestroyGameObject(float t) { yield return new WaitForSeconds(t); Destroy(gameObject); } }