private void OnCollisionEnter2D(Collision2D other) { if (other.gameObject.name.Contains("PowerUp") && currentPowerup.Equals(new KeyValuePair <string, float>())) // basically if null { currentPowerup = other.gameObject.GetComponent <PowerupController>().chosenPowerup; StartCoroutine(textDisplayer.ShowMessage("Powerup: " + currentPowerup.Key, currentPowerup.Value)); audio.PlayOneShot(a_powerup); remainingPowerupTime = currentPowerup.Value; other.gameObject.GetComponent <PowerupController>().powerUp(gameObject); // Can't be destroyed until powerup is over // Make powerup invisible and uncollidable and set the destroy timer to 11 (Longest powerup time is 10) other.gameObject.GetComponent <SpriteRenderer>().enabled = false; other.gameObject.GetComponent <BoxCollider2D>().enabled = false; Destroy(other.gameObject, 11); } else if (other.gameObject.name.Contains("GunBox")) { StartCoroutine(textDisplayer.ShowMessage("You found a new gun!", 2)); audio.PlayOneShot(a_powerup); int gunChoice = Random.Range(0, 2); if (gunChoice == 0) { GetComponentInChildren <Shoot>().gun = Gun.machinegun; } else { GetComponentInChildren <Shoot>().gun = Gun.shotgun; } Destroy(other.gameObject); } else if (other.gameObject.name.Contains("GunAmmo")) { if (GetComponentInChildren <Shoot>().gunAmmo == -1) { return; } StartCoroutine(textDisplayer.ShowMessage("You found ammo!", 2)); audio.PlayOneShot(a_powerup); GetComponentInChildren <Shoot>().gunAmmo += 10; Destroy(other.gameObject); } else if (other.gameObject.name.Contains("FlareAmmo")) { if (GetComponentInChildren <Shoot>().flareAmmo == -1) { return; } StartCoroutine(textDisplayer.ShowMessage("You found flare Ammo!", 2)); audio.PlayOneShot(a_powerup); GetComponentInChildren <Shoot>().flareAmmo += 1; Destroy(other.gameObject); } if (other.gameObject.name.Contains("Player")) { StartCoroutine(textDisplayer.ShowMessage("You win!", 5)); audio.PlayOneShot(a_win); StartCoroutine(endGame()); } }