void OnTriggerEnter2D(Collider2D other) { //Debug.Log(other.name); if (other.gameObject.CompareTag("Army")) { //TODO better initialization to avoid this check if (other.gameObject.GetComponentInParent <PlayerInfo>() != null && other.gameObject.GetComponentInParent <PlayerInfo>().PlayerName != playerInfo.PlayerName) { bool found = false; foreach (KeyValuePair <GameObject, AttackParabola> KV in parabolasList) { if (KV.Key == other.gameObject) { found = true; } } if (!found) { AttackParabola attackParabola = SingletonAllocator <AttackParabola> .GetInstance().GetFromPool(); parabolasList.Add(new KeyValuePair <GameObject, AttackParabola>(other.gameObject, attackParabola)); attackParabola.Setup(this.gameObject.transform.position, other.gameObject.transform.position, _attackMaterial); attackParabola.EnableGameObject(); attackParabola.Draw(this.gameObject, other.gameObject, radius); } } } }
void OnTriggerExit2D(Collider2D other) { foreach (KeyValuePair <GameObject, AttackParabola> KV in parabolasList) { if (KV.Key == other.gameObject) { parabolasList.Remove(KV); KV.Value.DisableGameObject(); SingletonAllocator <AttackParabola> .GetInstance().Free(KV.Value); break; } } }
void Awake() { AttackParabolaAllocator = SingletonAllocator <AttackParabola> .GetInstance(); }
void OnDestroy() { SingletonAllocator <AttackParabola> .GetInstance().Dispose(); }