using mh; using MH; using System.Collections; using System.Collections.Generic; using UnityEngine; public class SpiritScript : UnitBase { public float speed = 10f; public Item_Coin coinPrefab; public int count = 0; private FastCircleCollider collider; private static List collisions = new List(); protected override void Awake() { base.Awake(); collider = GetComponent(); } protected override void Update() { base.Update(); UnitBase hero = UnitManager.hero; Vector2 pos = transform.position; Vector2 heroPos = hero.transform.position; Vector2 dir = (heroPos - pos).normalized; pos += dir * Time.deltaTime * speed; this.GetComponent().flipX = dir.x < 0; collisions.Clear(); if (TestQuadtree.quadtree.Retrieve(ref collisions, collider)) { count = collisions.Count; } else { transform.position = pos; } } public void Die() { Item_Coin coin = Instantiate(coinPrefab) as Item_Coin; coin.transform.position = this.transform.position; this.gameObject.SetActive(false); Destroy(this.gameObject); } }