private GameObject healthCanvas; // Used to disable the world space UI during the Starting and Ending phases of each round. public void Setup() { Debug.LogFormat("Setting up player '{0}' as player {1}", playerName, playerNumber); // Get references to the components. tankMovement = instance.GetComponent <NetworkTankMovement>(); tankShooting = instance.GetComponent <NetworkTankShooting>(); tankHealth = instance.GetComponent <NetworkTankHealth>(); tankSkill = instance.GetComponent <AbstractNetworkSkill>(); tankConfig = instance.GetComponent <NetworkTankConfig>(); healthCanvas = instance.GetComponentInChildren <Canvas>().gameObject; // Get references to the child objects. tankRenderers = tankHealth.m_TankRenderers; //Set a reference to that amanger in the health script, to disable control when dying tankHealth.m_TankManager = this; // Set the player numbers to be consistent across the scripts. tankMovement.m_PlayerNumber = playerNumber; tankShooting.m_PlayerNumber = playerNumber; tankSkill.m_PlayerNumber = playerNumber; tankConfig.color = playerColor; tankConfig.playerName = playerName; tankConfig.playerNumber = playerNumber; }
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); }