private void SwingSword() { SwitchToSword(); Bounds swordColBounds = swordAttackCollider.bounds; Collider[] hitColliders = Physics.OverlapBox(swordColBounds.center, swordColBounds.extents, swordAttackCollider.transform.rotation, swordAttackMask); List <Enemy> affectedEnemies = new List <Enemy>(); foreach (Collider col in hitColliders) { EnemyLimbProxy enemyProxy = col.GetComponent <EnemyLimbProxy>(); if (enemyProxy != null && !affectedEnemies.Contains(enemyProxy.enemyScript)) { affectedEnemies.Add(enemyProxy.enemyScript); } } //Deal damage to all the enemies hit foreach (Enemy enemyScript in affectedEnemies) { if (enemyScript != null) { enemyScript.TakeDamage(swordDamage); Vector3 particlesLocation = enemyScript.gameObject.transform.position + Vector3.up * slashParticlesYOffset; if (slashParticlesPrefab != null) { Instantiate(slashParticlesPrefab, particlesLocation, Quaternion.identity); } } } if (affectedEnemies.Count > 0) { if (swordImpactSound != null) { audioSource.PlayOneShot(swordImpactSound); } } else { if (swordSwingSound != null) { audioSource.PlayOneShot(swordSwingSound); } } playerAnimController.MeleeAttackTrigger(); lastSwordSwingTime = Time.time; }
protected override void HandleCollision(RaycastHit hit) { EnemyLimbProxy enemyProxy = hit.collider.GetComponent <EnemyLimbProxy>(); if (enemyProxy != null) { enemyProxy.TakeDamage(damage); Vector3 particlePosition = enemyProxy.enemyScript.transform.position; particlePosition.y = transform.position.y; Instantiate(hitParticles, particlePosition, Quaternion.identity); } GlobalAudioPlayer.Instance.PlayClipAt(impactSound, transform.position, 1f); Destroy(gameObject); }
private void Explode(Vector3 origin) { Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius, explosionMask); List <Enemy> affectedEnemies = new List <Enemy>(); List <Rigidbody> affectedRigidbodies = new List <Rigidbody>(); foreach (Collider col in colliders) { EnemyLimbProxy enemyProxy = col.GetComponent <EnemyLimbProxy>(); if (enemyProxy != null && !affectedEnemies.Contains(enemyProxy.enemyScript)) { affectedEnemies.Add(enemyProxy.enemyScript); } Rigidbody rb = col.attachedRigidbody; //Dont add force to hurt colliders if (rb != null && !affectedRigidbodies.Contains(rb) && col.gameObject.layer != LayerMask.NameToLayer("EnemyHurtCollider")) { affectedRigidbodies.Add(rb); } } //Deal damage to all the enemies hit foreach (Enemy enemyScript in affectedEnemies) { if (enemyScript != null) { enemyScript.TakeDamage(damage); } } //Add the force with delay after rigidbodies are registered and damage delt StartCoroutine(ExecuteQueuedExplosion(affectedRigidbodies, origin)); //Play explosion sound and effect GlobalAudioPlayer.Instance.PlayClipAt(explosionSound, origin, explosionSoundScale); GameObject tempEffect = Instantiate(explosionEffect, origin, Quaternion.identity); Destroy(tempEffect, 5f); }
protected override void HandleCollision(RaycastHit hit) { EnemyLimbProxy enemyProxy = hit.collider.GetComponent <EnemyLimbProxy>(); if (enemyProxy != null) { enemyProxy.TakeDamage(damage); } //Audio if (hit.collider.gameObject.layer == LayerMask.NameToLayer("EnemyHurtCollider") || hit.collider.gameObject.layer == LayerMask.NameToLayer("EnemyRagdoll")) { GlobalAudioPlayer.Instance.PlayClipAt(impactSound_Flesh, hit.point, impactSoundScale_Flesh); } else { GlobalAudioPlayer.Instance.PlayClipAt(impactSound_Object, hit.point, impactSoundScale_Object); } Destroy(gameObject); }
private void Explode(Vector3 origin) { Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius, explosionMask); List <Enemy> affectedEnemies = new List <Enemy>(); foreach (Collider col in colliders) { EnemyLimbProxy enemyProxy = col.GetComponent <EnemyLimbProxy>(); if (enemyProxy != null && !affectedEnemies.Contains(enemyProxy.enemyScript)) { affectedEnemies.Add(enemyProxy.enemyScript); } } //Deal damage to all the enemies hit foreach (Enemy enemyScript in affectedEnemies) { if (enemyScript != null) { enemyScript.TakeDamage(impactDamage); enemyScript.Ignite(igniteTotalDamage, igniteDuration); } } //Play explosion sound and effect if (explosionSound != null) { GlobalAudioPlayer.Instance.PlayClipAt(explosionSound, origin, explosionSoundScale); } if (explosionEffect != null) { GameObject tempEffect = Instantiate(explosionEffect, origin, Quaternion.identity); Destroy(tempEffect, 5f); } Destroy(gameObject); }