void Shoot() { currentAmmoTracker.timer = 0f; EnableEffects(); Transform bulletTransform = transform; if (bulletSpec.shootSpread != 0) { bulletTransform.Rotate(new Vector3(0, 1, 0) * Random.Range(0, bulletSpec.shootSpread) * bulletSpreadDirection); bulletSpreadDirection *= -1; // Always ensure each successive bullet is rotated in the opposite direction } Rigidbody bullet = Instantiate(bulletPrefab, bulletTransform.position, bulletTransform.rotation * bulletPrefab.transform.rotation) as Rigidbody; if (!bulletSpec.isProjectile) { // Standard forward shooting bullet bullet.AddForce(bulletTransform.forward * bulletSpec.shootForce, ForceMode.Impulse); Destroy(bullet.gameObject, bulletSpec.bulletLifeTime); } else { // Lob type projectile bullet.velocity = playerRigidBody.velocity * 0.6f; bullet.AddForce(bulletTransform.forward * bulletSpec.shootForce + new Vector3(0f, 1f, 0f) * bulletSpec.liftForce, ForceMode.Impulse); bullet.AddTorque(new Vector3(1f, 0f, 0f) * bulletSpec.forwardTorque, ForceMode.Impulse); } currentAmmoTracker.ExpendAmmo(); ammoUI.UpdateAmmo(currentAmmoTracker); Invoke("DisableEffects", effectsDisplayTime); BulletTracker.AmmoShot(bulletSpec); }
protected virtual void OnCollisionEnter(Collision other) { ParticleSystem hitParticles = Instantiate(hitParticlesPrefab, other.contacts [0].point, hitParticlesPrefab.transform.rotation) as ParticleSystem; hitParticles.Play(); Destroy(hitParticles.gameObject, 0.3f); EnemyHealth enemyHealth = other.collider.GetComponent <EnemyHealth> (); if (enemyHealth != null) { // Special cases if (enemyHealth.enemyName == "ZomBear" && bulletName == "Pulse Rifle") { enemyHealth.TakeDamage(damagePerShot / 3); // ZomBear has resistance to pulse rifle } else if (enemyHealth.enemyName == "AttackBot" && (bulletName == "Assault Rifle" || bulletName == "Revolver")) { enemyHealth.TakeDamage(damagePerShot / 2); // AttackBot has resistance to mechanical bullets } else { enemyHealth.TakeDamage(damagePerShot); } BulletTracker.AmmoHit(this); } Destroy(gameObject); }
public void CollectWeapon(Rigidbody newBulletPrefab) { BulletTracker.CollectAmmo(newBulletPrefab.GetComponent <BulletSpec> ()); // Find through currently obtained weapons to add the ammo for (int i = 0; i < ammoTrackerList.Count; i++) { AmmoTracker ammoTracker = ammoTrackerList[i]; if (ammoTracker.AddAmmo(newBulletPrefab)) // We have this weapon already. Add ammo. { if (ammoTrackerListIndex == i) // Only update UI if currently showing this gun { ammoUI.UpdateAmmo(ammoTracker); gunAudio.clip = bulletSpec.shootAudio; // Restore shooting sound (in case ammo was empty) } return; } } { // Cannot find -> this is a new weapon, add new AmmoTracker ammoTrackerList.Add(new AmmoTracker(newBulletPrefab)); AmmoTracker ammoTracker = ammoTrackerList[ammoTrackerList.Count - 1]; // Update currentAmmoTracker and UI if this is the 1st weapon collected if (ammoTrackerListIndex == ammoTrackerList.Count - 1) { EquipWeapon(ammoTracker); } } }
public void TakeDamage(string enemyName, int value) { if (!isDead && !win) { currentHealth -= value; healthUI.TakeDamage(value); playerAudio.Play(); if (currentHealth <= 0 && !isDead) { Death(); } BulletTracker.EnemyDamage(enemyName, value); } }
void OnParticleCollision(GameObject other) { int numCollisionEvents = bulletParticleSystem.GetCollisionEvents(other, collisionEvents); if (numCollisionEvents > 0) { ParticleSystem hitParticles = Instantiate(hitParticlesPrefab, collisionEvents[0].intersection, hitParticlesPrefab.transform.rotation) as ParticleSystem; hitParticles.Play(); Destroy(hitParticles.gameObject, 0.3f); } EnemyHealth enemyHealth = other.GetComponent <EnemyHealth> (); if (enemyHealth != null) { enemyHealth.TakeDamage(damagePerShot); BulletTracker.AmmoHit(this); } }
public void Explode() { explosionAudio.Play(); explosionParticles.Play(); bool enemyHit = false; Collider[] hitColliders = Physics.OverlapSphere(transform.position, explosionRadius); int i = 0; while (i < hitColliders.Length) { EnemyHealth_Hellephant hellephantHealth = hitColliders[i].GetComponent <EnemyHealth_Hellephant> (); if (hellephantHealth != null && !hitColliders[i].isTrigger) { if (!hellephantHealth.IsSecondForm()) { hellephantHealth.TakeDamage(explosionDamage); enemyHit = true; } } else { EnemyHealth enemyHealth = hitColliders[i].GetComponent <EnemyHealth> (); if (enemyHealth != null && !hitColliders[i].isTrigger) { enemyHealth.TakeDamage(explosionDamage); enemyHit = true; } } i++; } if (enemyHit) { BulletTracker.AmmoHit("Grenade Launcher"); } Destroy(gameObject, 5f); }
public void AddScore(int value, string enemyName, Transform enemyPosition) { if (!enemyName.Equals("")) // Avoid adding a kill to blank during initialisation { BulletTracker.EnemyKill(enemyName); } score_ += value; scoreText_.text = "Score: " + score_; // PowerUp drop algo if (enemyName == "ZomBunny") { count_zombunny_kills_++; if (GameConfig.difficulty == GameConfig.Difficulty.Hardcore) { if (count_zombunny_kills_ % count_zombunny_drop_pulse == 0) { DropPowerUp(powerup_PulseRifle_, enemyPosition); } else if (count_zombunny_kills_ % count_zombunny_drop_AR == 0) { DropPowerUp(powerup_AssaultRifle_, enemyPosition); } } else { if (count_zombunny_kills_ % count_zombunny_drop_AR == 0) { DropPowerUp(powerup_AssaultRifle_, enemyPosition); } else if (count_zombunny_kills_ % count_zombunny_drop_pulse == 0) { DropPowerUp(powerup_PulseRifle_, enemyPosition); } } } else if (enemyName == "ZomBear") { count_zombear_kills_++; if (count_zombear_kills_ % count_zombear_drop_health == 0) { DropPowerUp(powerup_Health_, enemyPosition); } else if (count_zombear_kills_ % count_zombear_drop_grenade == 0) { DropPowerUp(powerup_GrenadeLauncher_, enemyPosition); } } else if (enemyName == "AttackBot") { count_attackBot_kills_++; } // Game state algo if (enemyName.Equals("ZomBunny") || enemyName.Equals("")) { if (GameConfig.gameMode == GameConfig.GameMode.Campaign) { UpdateGameState_Campaign(); } else if (GameConfig.gameMode == GameConfig.GameMode.Survival) { UpdateGameState_Survival(); } } }
void Awake() { BulletTracker.Clear(); }