void Shoot() { RaycastHit hit; GameObject effectIns = Instantiate(muzzleFlash, transform.position, transform.rotation); FindObjectOfType <AudioManager>().Play("Shot1"); Destroy(effectIns, 1f); rayDelay = false; if (Physics.Raycast(Gun.transform.position, Gun.transform.forward, out hit, range)) { DestructibleObj enemy = hit.transform.GetComponent <DestructibleObj>(); if (enemy != null && enemy.tag != "Player") { damage = (int)RandomDmg(); eventLog.NewActivity(("You hit " + enemy.name + " for " + damage)); enemy.DamageIncome(damage); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(-hit.normal * impactForce); } GameObject ImpactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(ImpactGO, 1f); } }
public void DamageOutcome(float DestroyDamage) { Collider[] collidersToDestroy = Physics.OverlapSphere(transform.position, DestroyRadius); foreach (Collider nearbyObject in collidersToDestroy) { DestructibleObj dest = nearbyObject.GetComponent <DestructibleObj>(); if (dest != null) { dest.DamageIncome(DestroyDamage); } } Collider[] collidersToMove = Physics.OverlapSphere(transform.position, DestroyRadius); foreach (Collider nearbyObject in collidersToMove) { Rigidbody rb = nearbyObject.GetComponent <Rigidbody>(); if (rb != null) { rb.AddExplosionForce(DestroyForce, transform.position, DestroyRadius); } } }