private void OnTriggerEnter(Collider other) { // Collect all the colliders in a sphere from the shell's current position to a radius of the explosion radius. Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask); // Go through all the colliders... for (int i = 0; i < colliders.Length; i++) { // ... and find their rigidbody. Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>(); // If they don't have a rigidbody, go on to the next collider. if (!targetRigidbody) { continue; } // Find the TankHealth script associated with the rigidbody. NetworkTankHealth targetHealth = targetRigidbody.GetComponent <NetworkTankHealth>(); // If there is no TankHealth script attached to the gameobject, go on to the next collider. if (!targetHealth) { continue; } // Calculate the amount of damage the target should take based on it's distance from the shell. float damage = CalculateDamage(targetRigidbody.position); // Deal this damage to the tank. targetHealth.TakeDamage(damage); } if (!NetworkClient.active) //if we are ALSO client (so hosting), this will be done by the Destroy so Skip { AddExplosionForce(); } // Destroy the shell on clients as well. NetworkServer.Destroy(gameObject); }
private void OnTriggerEnter(Collider other) { if (!active) { return; } // Find all the tanks in an area around the fist and damage them. //Get all coliders in the radius of the exploding fist Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask); foreach (var c in colliders) { Rigidbody targetRigidBody = c.GetComponent <Rigidbody>(); if (!targetRigidBody) { continue; } // Find the TankHealth script associated with the rigidbody. NetworkTankHealth targetHealth = targetRigidBody.GetComponent <NetworkTankHealth>(); if (!targetHealth) { continue; } float damage = CalculateDamage(targetRigidBody.position); targetHealth.TakeDamage(damage); } if (!NetworkClient.active) { AddExplosionForce(); } NetworkServer.Destroy(gameObject); }