private void OnCollisionEnter2D(Collision2D collision) { if (!invincible) { // TODO readability if (lastSpeed > 5f && collision.collider.tag != "Cargo" && collision.collider.tag != "Asteroid" && collision.collider.tag != "Bounds" && collision.collider.tag != "Debris") { health -= lastSpeed * 10; if (health < 0) { if (magData.magnetizedList.Contains(mag)) { mag.DeMagnetize(); } magData.DestroyMagnetizable(mag); // TODO ObjectPool temp = ObjectPool.instance.GetObjectForType(type); temp.transform.position = transform.position; temp.transform.rotation = Quaternion.identity; PoolMe(); } } } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Cargo")) { GuideSystem.instance?.SoldCargo(); LevelManager.instance.LevelScore += collision.transform.GetComponent <Cargo>().value; LevelManager.instance?.cargoSpawner.SpawnCargo(); Magnetizable _mag = collision.GetComponentInChildren <Magnetizable>(); if (_mag.magnetizedTo != null) { _mag.DeMagnetize(); } AudioManager.instance.Play("Reward"); PoolMe(collision.gameObject); // TODO } }
private void OnCollisionEnter2D(Collision2D collision) { if (!invincible) { if (lastSpeed > 5f && collision.collider.tag != "Cargo" && collision.collider.tag != "Asteroid" && collision.collider.tag != "Bounds" && collision.collider.tag != "Debris") { health -= lastSpeed * 10; if (health < 0) { if (magData.magnetizedList.Contains(mag)) { mag.DeMagnetize(); } magData.DestroyMagnetizable(mag); Instantiate(explodePrefab, transform.position, Quaternion.identity); Destroy(gameObject); } } } }