void Attack() { // Reset the timer. timer = 0f; // If the player has health to lose... if (playerHealth.CurrentHealth > 0) { // ... damage the player. playerHealth.TakeDamage(attackDamage); } }
private void OnTriggerEnter(Collider other) { if (other.tag.Equals("Canister") || other.tag.Equals("Shield")) { } else { // Find the TankHealth script associated with the rigidbody. Complete.TankHealth targetHealth = other.GetComponent <Complete.TankHealth>(); // If there is no TankHealth script attached to the gameobject, go on to the next collider. if (!targetHealth) { Destroy(gameObject); return; } // Deal this damage to the tank. targetHealth.TakeDamage(damage); Destroy(gameObject); } }
private void OnTriggerEnter(Collider other) { if (other.gameObject.tag.Equals("Tank") == true) { m_ObjectCollider.isTrigger = true; Debug.Log("Tank"); // 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; } // 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. targetHealth.TakeDamage(damage); } // 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. ParticleSystem.MainModule mainModule = m_ExplosionParticles.main; Destroy(m_ExplosionParticles.gameObject, mainModule.duration); // Destroy the shell. Destroy(gameObject); } else if (other.gameObject.tag.Equals("Wall") == true) { Debug.Log("Wall"); //reflectedObject.position = Vector3.Reflect(originalObject.position, Vector3.right); m_ObjectCollider.isTrigger = false; StartCoroutine(wait()); } }
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; } // 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. targetHealth.TakeDamage(damage); // add to damage report, so we can send to listensers // note that tank might damage itself, so we need to add all damages ITankAgent agent = targetRigidbody.GetComponent <ITankAgent>(); if (agent == null) { continue; } if (damageReport.ContainsKey(agent.GetPlayerNumber())) { // if multiple parts of the tank are hit, we need to add up all the damage damageReport[agent.GetPlayerNumber()] += damage; } else { damageReport.Add(agent.GetPlayerNumber(), damage); } } // once all damages are calculated, send out damage report if (OnExplosion != null) { OnExplosion.Invoke(this, damageReport); } // 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. ParticleSystem.MainModule mainModule = m_ExplosionParticles.main; Destroy(m_ExplosionParticles.gameObject, mainModule.duration); // Destroy the shell. Destroy(gameObject); }
public void OnTriggerEnter(Collider other) { if (aktiv == true) { exploded = true; //DestroyImmediate(gameObject); //transform.localScale = new Vector3(transform.localScale.x + 5, transform.localScale.y + 5, transform.localScale.z + 5); // Collect all the colliders in a sphere from the shell's current position to a radius of the explosion radius. Collider[] collidersTank = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask); Collider[] collidersMine = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_MineMask); for (int i = 0; i < collidersMine.Length; i++) { MineExplosion mine = collidersMine [i].GetComponent <MineExplosion> (); if (mine.exploded != true) { mine.exploded = true; } } // Go through all the colliders... for (int i = 0; i < collidersTank.Length; i++) { // ... and find their rigidbody. Rigidbody targetRigidbody = collidersTank [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. targetHealth.TakeDamage(damage); } // 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. Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.duration); // Destroy the mine. Destroy(gameObject); } }
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_tank = colliders[i].GetComponent<Rigidbody> (); //Rigidbody targetRigidbody_chicken = colliders[i].GetComponent<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_tank.AddExplosionForce (m_ExplosionForce, transform.position, m_ExplosionRadius); // targetRigidbody_chicken.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius); targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius); // Find the TankHealth script associated with the rigidbody. TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth> (); ChickenHealth chickenHealth = targetRigidbody.GetComponent <ChickenHealth>(); // If there is no TankHealth script attached to the gameobject, go on to the next collider. if (!(targetHealth || chickenHealth)) { continue; } //if (!chickenHealth) // 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. if (targetHealth) { targetHealth.TakeDamage(damage); } else if (chickenHealth) { chickenHealth.TakeDamage(damage); } } // 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. ParticleSystem.MainModule mainModule = m_ExplosionParticles.main; Destroy(m_ExplosionParticles.gameObject, mainModule.duration); // Destroy the shell. Destroy(gameObject); }
private void OnTriggerEnter(Collider other) { if (AlreadyHit) { return; } // 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; } // 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. targetHealth.TakeDamage(damage); } // 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. ParticleSystem.MainModule mainModule = m_ExplosionParticles.main; Destroy(m_ExplosionParticles.gameObject, mainModule.duration); // Destroy the shell. Invoke("Destroise", 1f); //fake destroy local. AlreadyHit = true; GetComponent <MeshRenderer>().enabled = false; GetComponent <Light>().enabled = false; }
private void calculateTankHealth(TankHealth tankTargetHealth, float damage) { // Deal this damage to the tank. tankTargetHealth.TakeDamage(damage); }