private void OnTriggerEnter(Collider other) { // Find all the tanks in an area around the shell and damage them. // 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); Collider[] remotecolliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_RemoteTankMask); // 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; } // Add an explosion force. targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius); // Find the TankHealth script associated with the rigidbody. TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth>(); // 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. //gets playerID and appends damage to them if (colliders[i].GetComponent <Collider>().tag == PLAYER_TAG) { if (!isServer) { //remotecolliders[i].GetComponent<NetworkIdentity>().AssignClientAuthority(this.GetComponent<NetworkIdentity>().connectionToClient); targetHealth.CmdTakeDamage(colliders[i].GetComponent <PlayerSetup>().NetID, damage); } //remotecolliders[i].gameObject.GetComponent<NetworkIdentity>().RemoveClientAuthority(this.GetComponent<NetworkIdentity>().connectionToClient); else { targetHealth.RpcTakeDamage(colliders[i].GetComponent <PlayerSetup>().NetID, damage); } } else { targetHealth.TakeDamage(damage); } } for (int i = 0; i < remotecolliders.Length; i++) { // ... and find their rigidbody. Rigidbody targetRigidbody = remotecolliders[i].GetComponent <Rigidbody>(); // If they don't have a rigidbody, go on to the next collider. if (!targetRigidbody) { continue; } // Add an explosion force. targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius); // Find the TankHealth script associated with the rigidbody. TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth>(); //TankHealth targetHealth; // 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. //gets playerID and appends damage to them if (remotecolliders[i].GetComponent <Collider>().tag == PLAYER_TAG) { if (!isServer) { //remotecolliders[i].GetComponent<NetworkIdentity>().AssignClientAuthority(this.GetComponent<NetworkIdentity>().connectionToClient); targetHealth.CmdTakeDamage(remotecolliders[i].GetComponent <PlayerSetup>().NetID, damage); } //remotecolliders[i].gameObject.GetComponent<NetworkIdentity>().RemoveClientAuthority(this.GetComponent<NetworkIdentity>().connectionToClient); else { targetHealth.RpcTakeDamage(remotecolliders[i].GetComponent <PlayerSetup>().NetID, damage); } } else { targetHealth.TakeDamage(damage); } } if (GameManager.IsOnline) { if (!isServer) { // Unparent the particles from the shell. m_ExplosionParticles.transform.parent = null; // Play the particle system. m_ExplosionParticles.Play(); // Play the explosion sound effect. m_ExplosionAudio.Play(); // Once the particles have finished, destroy the gameobject they are on. #pragma warning disable CS0618 // Type or member is obsolete Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.duration); #pragma warning restore CS0618 // Type or member is obsolete // Destroy the shell. Destroy(gameObject); } else { RpcShellstuff(); } } else { // Unparent the particles from the shell. m_ExplosionParticles.transform.parent = null; // Play the particle system. m_ExplosionParticles.Play(); // Play the explosion sound effect. m_ExplosionAudio.Play(); // Once the particles have finished, destroy the gameobject they are on. #pragma warning disable CS0618 // Type or member is obsolete Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.duration); #pragma warning restore CS0618 // Type or member is obsolete // Destroy the shell. Destroy(gameObject); } }