private void OnCollisionEnter(Collision other) { Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius, botMask); for (int i = 0; i < colliders.Length; i++) { Transform targetTransform = colliders[i].GetComponent <Transform>(); if (!targetTransform) { continue; } AIHealth targetHealth = targetTransform.GetComponent <AIHealth>(); BotManager botManager = targetTransform.GetComponent <BotManager>(); if (!targetHealth || !botManager) { continue; } targetHealth.TakeDamage(Weapon.TakeDamage); botManager.isOnAttack = true; break; } StartCoroutine(DestroyTimer()); }
protected virtual void OnTriggerEnter(Collider aCollider) { if (aCollider.gameObject.GetComponent <Bobble>() != null) { Bobble bobble = aCollider.gameObject.GetComponent <Bobble>(); bobble.ApplyImpulse(transform.forward); } if (aCollider.gameObject.GetComponent <AIHealth>() != null) { AIHealth ai = aCollider.gameObject.GetComponent <AIHealth>(); ai.TakeDamage(1, sourceObject.transform); Destroy(this.gameObject); } }
public void Explode() { GameObject eplxosionSFXClone = Instantiate(explosionEffect, explosionSpawnPoint.position, transform.rotation); Collider[] _colliders = Physics.OverlapSphere(transform.position, radius); { foreach (var nearbyObject in _colliders) { Prop prop = nearbyObject.GetComponent <Prop>(); Rigidbody rb = nearbyObject.GetComponent <Rigidbody>(); if (rb) { rb.AddExplosionForce(force, transform.position, radius); } if (prop) { prop.GetDamage(damage); } AIHealth aiHealth = nearbyObject.GetComponent <AIHealth>(); if (aiHealth) { aiHealth.TakeDamage(damage * 2, transform.position - aiHealth.transform.position, force); } InnocentHealth innocentHealth = nearbyObject.GetComponent <InnocentHealth>(); if (innocentHealth) { innocentHealth.TakeDamage(damage * 4, transform.position - innocentHealth.transform.position, force); } } GameEvents.events.CallExplosionSound(); Destroy(eplxosionSFXClone, 2.2f); Destroy(gameObject, 2.2f); } }
public void Shoot() { // Reset the timer. timer = 0f; // Play the gun shot audioclip. gunAudio.Play(); // Enable the lights. gunLight.enabled = true; faceLight.enabled = true; // Stop the particles from playing if they were, then start the particles. gunParticles.Stop(); gunParticles.Play(); // Enable the line renderer and set it's first position to be the end of the gun. gunLine.enabled = true; gunLine.SetPosition(0, transform.position); // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = transform.position; shootRay.direction = transform.forward; gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.SphereCast(shootRay, 1f, out shootHit, range, shootableMask)) { AIHealth enemyHealth = shootHit.collider.GetComponent <AIHealth>(); if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, shootHit.point); // shootHit.rigidbody.constraints &= RigidbodyConstraints.FreezeAll; if (shootHit.rigidbody != null) { } if (enemyHealth.currentHealth <= 0) { shootHit.rigidbody.isKinematic = true; Animator animator = shootHit.transform.gameObject.GetComponent <Animator>(); CapsuleCollider capsulCollider = shootHit.transform.gameObject.GetComponent <CapsuleCollider>(); Raggdoll ragdoll = shootHit.transform.gameObject.GetComponent <Raggdoll>(); if (animator != null && capsulCollider != null && capsulCollider.enabled == true) { ragdoll.enabledParts(); // capsulCollider.enabled = false; StartCoroutine(waitFrame(animator, ragdoll, capsulCollider)); } } } // Set the second position of the line renderer to the point the raycast hit. gunLine.SetPosition(1, shootHit.point); } // If the raycast didn't hit anything on the shootable layer... else { // ... set the second position of the line renderer to the fullest extent of the gun's range. gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }