private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Player") { pam.AlterAmmo(ammo); Destroy(gameObject); } }
IEnumerator FIRE() { foreach (GameObject spawnPoint in projectileSpawns) { if (sounds.Length > 0) { audioSource.PlayOneShot(sounds[Random.Range(0, sounds.Length)], 0.5f); } GameObject shot = Instantiate(projectile, spawnPoint.transform.position, transform.rotation); if (pam != null) { pam.AlterAmmo(-1); } Projectile currentP = shot.GetComponent <Projectile>(); if (isEnemy) { shot.tag = "EnemyProjectile"; shot.layer = 9; } else { shot.tag = "PlayerProjectile"; shot.layer = 10; } if (SpreadDamageOverBullets) { currentP.damage = (damage * damageMult) / projectileSpawns.Length; } else { currentP.damage = damage * damageMult; } currentP.flightSeed = projectileSpeed; if (AlternateBarrels) { yield return(new WaitForSeconds((fireRate / fireRateMult) / projectileSpawns.Length)); } } if (!AlternateBarrels) { yield return(new WaitForSeconds((fireRate / fireRateMult))); } firing = false; }
public void DropGun(bool removeSide = false) { if (!removeSide) { if (pam.guns[frontGunIndex] != null) { audio.PlayOneShot(dropGunSound); GameObject gunToDrop = pam.guns[frontGunIndex]; pam.guns[frontGunIndex] = null; gunToDrop.transform.SetParent(null); gunToDrop.GetComponentInChildren <SpriteRenderer>().color = Color.white; gunToDrop.GetComponent <Gun>().Dropped(); StartCoroutine("PickupDelay"); } } else { GameObject gunToDrop; int slotToRemove = 0; audio.PlayOneShot(gunLossSound); pam.AlterAmmo(-(pam.ammo / pam.sideCount)); //print("Front Gun Index = " + frontGunIndex); //prevents the player from losing their currently equipped gun if (frontGunIndex == pam.guns.Count - 1) { if (pam.guns[0] != null) { gunToDrop = pam.guns[0]; pam.guns[0] = null; //print("pam.guns.count = " + pam.guns.Count); } else { gunToDrop = null; } slotToRemove = 0; } else { gunToDrop = pam.guns[pam.guns.Count - 1]; pam.guns[pam.guns.Count - 1] = null; print("pam.guns.count = " + pam.guns.Count); slotToRemove = pam.guns.Count - 1; } if (gunToDrop != null) { gunToDrop.transform.SetParent(null); gunToDrop.GetComponentInChildren <SpriteRenderer>().color = Color.white; gunToDrop.GetComponent <Gun>().Dropped(); StartCoroutine("PickupDelay"); } pam.guns.RemoveAt(slotToRemove); if (frontGunIndex > pam.guns.Count - 1) { frontGunIndex = pam.guns.Count - 1; } } UpdateUIElements(); }