private void OnTriggerEnter(Collider other) { // Find all the tanks in an area around the shell and damage them. Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask); for (int i = 0; i < colliders.Length; ++i) { Rigidbody targetRigidbody = colliders [i].GetComponent <Rigidbody> (); if (!targetRigidbody) { continue; } targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius); TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth> (); if (!targetHealth) { continue; } float damage = CalculateDamage(targetRigidbody.position); targetHealth.TakeDamage(damage); } m_ExplosionParticles.transform.parent = null; //Make the particle system still work even if we destroyed a shell. m_ExplosionParticles.Play(); m_ExplosionAudio.Play(); //UnityEngine.ParticleSystem.duration is obselete, use main.duration instead Destroy(m_ExplosionParticles.gameObject.gameObject, m_ExplosionParticles.duration); // Destroy (m_ExplosionParticles.gameObject.gameObject, main.duration); Destroy(gameObject); }
private void OnTriggerEnter(Collider Other) // Find All TANKS in an area around a Shell and Damage Them. { Collider[] Colliders = Physics.OverlapSphere(transform.position, ExplosionRadius, TankMask); // Collect all the colliders in a sphere from the shell's current position to a radius of the explosion radius. int i; for (i = 0; i < Colliders.Length; i++) // Go through all Colliders. { Rigidbody TargetRigidBody = Colliders[i].GetComponent <Rigidbody>(); if (!TargetRigidBody) { continue; } TargetRigidBody.AddExplosionForce(ExplosionForce, transform.position, ExplosionRadius); // Add an explosion force to the FOUND Shell. TankHealth TargetHealth = TargetRigidBody.GetComponent <TankHealth>(); // Find the TankHealth script associated with the rigidbody. if (!TargetHealth) { continue; } float Damage = CaculateDamage(TargetRigidBody.position); // Calculate the Amount of damage. TargetHealth.TakeDamage(Damage); // Apply the Damage To the TANK. } ExplosionParticles.transform.parent = null; // Unparent the particles from the shell. ExplosionParticles.Play(); ExplosionAudio.Play(); Destroy(ExplosionParticles.gameObject, ExplosionParticles.main.duration); // Once the particles have finished, destroy the gameobject they are on. Destroy(gameObject); // Destroy the shell. }
private void OnTriggerEnter(Collider other) { // Find all the tanks in an area around the shell and damage them. Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask); for (int i = 0; i < colliders.Length; i++) { Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>(); if (!targetRigidbody) { continue; } targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius); TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth>(); if (!targetHealth) { continue; } float damage = CalculateDamage(targetRigidbody.position); targetHealth.TakeDamage(damage); } m_ExplosionParticles.transform.parent = null; m_ExplosionParticles.Play(); m_ExplosionAudio.Play(); Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.main.duration); Destroy(gameObject); }
private void OnCollisionEnter(Collision other) { // Find the Rigidbody of the collision object Rigidbody targetRigidbody = other.gameObject.GetComponent <Rigidbody>(); // Only tanks will have Rigidbody scripts if (targetRigidbody != null) { // 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 (targetHealth != null) { // 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(); // Once the particles have finished, destroy the gameObject they are on Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.main.duration); // Destroy the shell Destroy(gameObject); }
private void OnTriggerEnter(Collider other) { // Find all the tanks in an area around the shell and damage them. Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask); //TankMask used to only pick up tanks for (int i = 0; i < colliders.Length; i++) { Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>(); if (!targetRigidbody) //Sanity check { continue; } targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius); TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth>(); if (!targetHealth) //Sanity check { continue; } float damage = CalculateDamage(targetRigidbody.position); targetHealth.TakeDamage(damage); } m_ExplosionParticles.transform.parent = null; //So it still plays after the shell is destroyed m_ExplosionParticles.Play(); m_ExplosionAudio.Play(); Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.duration); //We want to destroy the game object, not the component (m_ExplosionParticles) Destroy(gameObject); }
private void OnTriggerEnter(Collider other) { // Find all the tanks in an area around the shell and damage them. if (m_Exploded) { return; } Vector3 triggerPosition = transform.position; Collider[] colliders = Physics.OverlapSphere(triggerPosition, m_ExplosionRadius, m_TankMask.value); foreach (Collider collider in colliders) { float damage = CalculateDamage(collider.transform.position); TankHealth hitTankHealth = collider.gameObject.GetComponent <TankHealth> (); hitTankHealth.TakeDamage(damage); Rigidbody hitRigidbody = collider.gameObject.GetComponent <Rigidbody> (); hitRigidbody.AddExplosionForce(m_ExplosionForce, triggerPosition, m_ExplosionRadius); } m_ExplosionParticles.Play(); m_ExplosionAudio.Play(); MeshRenderer meshRenderer = GetComponent <MeshRenderer> (); meshRenderer.enabled = false; Rigidbody rigidbody = GetComponent <Rigidbody> (); rigidbody.isKinematic = true; Destroy(gameObject, 1f); }
private void OnTriggerEnter(Collider other) { // Find all the tanks in an area around the shell and damage them. Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask); for (int i = 0; i < colliders.Length; i++) { Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>(); if (!targetRigidbody) { continue; } targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius); TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth> (); if (!targetHealth) { continue; } float damage = CalculateDamage(targetRigidbody.position); targetHealth.TakeDamage(damage); } // Desacnlo el sistema de aprticulas de la bomba. m_ExplosionParticles.transform.parent = null; // Reproduczco el sistema de pertículas. m_ExplosionParticles.Play(); // Reproduzco el audio. m_ExplosionAudio.Play(); // Cuando las partículas han terminado, destruyo su objeto asociado. Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.main.duration); // Destruyo la bomba. Destroy(gameObject); }
private void OnTriggerEnter(Collider other) { if (!photonView.IsMine) { return; } // Find all the tanks in an area around the shell and damage them. Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask); for (int i = 0; i < colliders.Length; i++) { Rigidbody targetRigibody = colliders[i].GetComponent <Rigidbody>();//抓取爆炸半徑內的Rigidbody if (!targetRigibody) { continue; } targetRigibody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius); TankHealth targetHealth = targetRigibody.GetComponent <TankHealth>(); if (!targetHealth) { continue; } float damage = CalculateDamage(targetRigibody.position); targetHealth.TakeDamage(damage); } StartCoroutine(Explsion()); }
private void ExplodeShell() { // Find all the tanks in an area around the shell and damage them. var colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask); foreach (var collider in colliders) { var targetRigidBody = collider.GetComponent <Rigidbody>(); if (!targetRigidBody) { continue; } targetRigidBody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius); TankHealth targetHealth = targetRigidBody.GetComponent <TankHealth>(); if (!targetHealth) { continue; } float damage = CalculateDamage(targetRigidBody.position); targetHealth.TakeDamage(damage); } }
/////////////////////////// void OnTriggerEnter(Collider other) { if (m_isFirst) { return; } m_isFirst = true; // 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); for (int i = 0; i < colliders.Length; i++) { Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>(); if (!targetRigidbody) { continue; } TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth>(); if (!targetHealth) { continue; } if (targetHealth.m_isImmortal) { continue; } if (PhotonNetwork.IsMasterClient) { float damage = CalculateDamage(targetRigidbody.position); targetHealth.TakeDamage(damage, m_teamIndex, transform.position, m_ExplosionForce, m_ExplosionRadius); } } m_ExplosionParticles.transform.parent.parent = null; m_ExplosionParticles.Play(); m_audio.Play(); GameObject.Destroy(gameObject); }
private void Update() { // Store the player's input and make sure the audio for the engine is playing. m_MovementInputValue = Input.GetAxis(m_MovementAxisName); m_TurnInputValue = Input.GetAxis(m_TurnAxisName); EngineAudio(); //pruebas if (Input.GetKey(KeyCode.K)) { THScript.TakeDamage(2f); } //if (Input.GetKey(KeyCode.W)) { movement = transform.forward * 1 * slowAc * Time.deltaTime; } if (Input.GetKey(KeyCode.S)) { LastInput = "S"; } if (Input.GetKey(KeyCode.W)) { LastInput = "W"; } }
public override bool IsFinished() { m_Timer += Time.deltaTime; if (m_Timer < 1) { return(false); } else if (m_Timer >= 1 && !m_IsExploded) { m_Explosion = GameObject.Instantiate(m_ExplosionPrefab); var explosionParticles = m_Explosion.GetComponent <ParticleSystem>(); explosionParticles.transform.position = m_RigidBody.transform.position; explosionParticles.Play(); m_RigidBody.AddForce(Vector3.up * 150); if (m_Health.CurrentHealth > 10) { m_Health.TakeDamage(10); } m_IsExploded = true; GameObject.Destroy(m_Explosion, explosionParticles.duration); return(false); } else if (m_Timer >= 1.1 && m_IsExploded) { return(true); } else { return(false); } }
private void Explosion(Collider collider) { explosionParticles.transform.parent = null; explosionParticles.Play(); Destroy(explosionParticles.gameObject, explosionParticles.main.duration); Destroy(gameObject); Rigidbody targetRigidbody = collider.GetComponent <Rigidbody>(); if (!targetRigidbody) { return; } TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth>(); if (targetRigidbody && targetHealth) { //タンクの場合HPを減らす targetHealth.TakeDamage(damage); } }
private void OnTriggerEnter(Collider other) //comes into picture whenanything comes in contact with it or intersected { // Find all the tanks in an area around the shell and damage them. Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask); //overlap sphere creates an imaginary sphere...anything that is inside that sphere is collected as collider.........tankmask is used so it only captures the tanks for (int i = 0; i < colliders.Length; i++) //now we iterate through each of the colliders { Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>(); //iterating through each collider inside the sphere....now it checks if that collider has a rigid bo if (!targetRigidbody) //if it doesnt have a rigid body it continues.....though every collider should have one...it is a safety measure in case { continue; } targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius); //this will add force according to three values force of explosion, position of the shell and radius i.e. how far the explosion can reach TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth>(); //if the collider with rigid body is the tank if (!targetHealth) //if the target is not the tank ....continue { continue; } float damage = CalculateDamage(targetRigidbody.position); //now we calculate the damage targetHealth.TakeDamage(damage); //calculates the tank's health after the damage } m_ExplosionParticles.transform.parent = null; m_ExplosionParticles.Play(); m_ExplosionAudio.Play(); Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.duration); Destroy(gameObject); }
void OnCollisionEnter(Collision other) { if (!other.collider.CompareTag(TargetTag) && other.gameObject.layer != LayerMask.NameToLayer("Ground")) { return; } Rigidbody targetRigidbody = other.rigidbody; //- Damage target here if (targetRigidbody != null) { targetRigidbody.AddExplosionForce(ExplosionForce, transform.position, ExplosionRadius); TankHealth targetHealth = targetRigidbody .GetComponent <TankHealth>(); if (targetHealth != null) { float damage = CalculateDamage(targetRigidbody.position); targetHealth.TakeDamage(damage); } } //- ExplosionSystem.transform.SetParent(null); ExplosionSystem.Play(); Destroy(ExplosionSystem.gameObject, ExplosionSystem.duration); Destroy(gameObject); }
private void OnTriggerEnter(Collider other) { if (other.tag == "projectile") { return; } // get team ID int idTeamShooter = m_Shooter.GetComponent <TeamInfo>().IDTeam; // id of collider int idTeamCollider = other.GetComponent <TeamInfo>().IDTeam; // owner id if (idTeamCollider == idTeamShooter) { return; } // not target if (other.gameObject != Target) { 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. //Destroy (m_ExplosionParticles.gameObject, m_ExplosionParticles.duration); // Find the TankHealth script associated with the rigidbody. TankHealth targetHealth = other.GetComponent <TankHealth>(); // If there is no TankHealth script attached to the gameobject, go on to the next collider. if (targetHealth) { // Calculate the amount of damage the target should take based on it's distance from the shell. float damage = m_Shooter.GetComponent <TankShooting>().damage; // Deal this damage to the tank. targetHealth.TakeDamage(damage); } // Destroy the shell. Destroy(gameObject); }
private void OnTriggerEnter(Collider other) { // Find all the tanks in an area around the shell and damage them. Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius); // 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) { //targetRigidbody.AddExplosionForce (m_ExplosionForce, transform.position, m_ExplosionRadius,3.0f); } // Add an explosion force. Destructible buildingDes = colliders[i].GetComponent <Destructible> (); if (buildingDes) { buildingDes.TakeDamage(50); } // Find the TankHealth script associated with the rigidbody. TankHealth targetHealth = colliders[i].GetComponent <TankHealth> (); // If there is no TankHealth script attached to the gameobject, go on to the next collider. if (!targetHealth) { continue; } else { } // Calculate the amount of damage the target should take based on it's distance from the shell. float damage = CalculateDamage(colliders[i].transform.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(); m_ExplosionAudioEvent.Play(m_ExplosionAudio); // Once the particles have finished, destroy the gameobject they are on. Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.main.duration); // Destroy the shell. Destroy(gameObject); }
protected override void OnTriggerEnter(Collider other) { if (m_TankMask.value == 1 << other.gameObject.layer && m_PassedLauncher) { // Find all the tanks in an area around the shell and damage them. Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask); for (int i = 0; i < colliders.Length; i++) { Rigidbody targetRigidbody = colliders [i].GetComponent <Rigidbody> (); if (!targetRigidbody) { continue; } targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius); TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth> (); if (!targetHealth) { continue; } float damage = CalculateDamage(targetRigidbody.position); targetHealth.TakeDamage(damage); } m_ExplosionParticles.transform.parent = null; m_ExplosionParticles.Play(); m_ExplosionAudio.Play(); Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.main.duration); Destroy(gameObject); } else if (m_PortalMask.value == 1 << other.gameObject.layer) { Vector3 rotationAxis = other.gameObject.transform.right; transform.RotateAround(m_SpriteTransform.position, rotationAxis, 90f); transform.position += other.gameObject.transform.forward * 0.5f; Vector3 upOffset = other.gameObject.transform.up * 11.1f; if (upOffset.x > 1f || upOffset.x < -1f) { Vector3 newTransform = new Vector3(upOffset.x, transform.position.y, transform.position.z); transform.position = newTransform; } else if (upOffset.y > 1f || upOffset.y < -1f) { Vector3 newTransform = new Vector3(transform.position.x, upOffset.y, transform.position.z); transform.position = newTransform; } else if (upOffset.z > 1f || upOffset.z < -1f) { Vector3 newTransform = new Vector3(transform.position.x, transform.position.y, upOffset.z); transform.position = newTransform; } } }
private void OnCollisionEnter(Collision collision) { if (collision.collider.tag == "Tank") { Debug.Log("Y'a eu trigger avec " + collision.collider.name); Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius); for (int i = 0; i < colliders.Length; i++) { Debug.Log("JAI touché " + colliders[i].name); Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>(); Rigidbody parentTry = colliders[i].GetComponentInParent <Rigidbody>(); // Si le parent de l'element a pas de rigidbody c'est pas un bout du tank, donc on passe au suivant. if (!parentTry) { continue; } //Si on trouve pas le tag tank, on a rien a faire donc on continue if (parentTry.tag != "Tank") { continue; } PilotController scriptpilote = parentTry.GetComponent <PilotController>(); if (scriptpilote) { if (colliders[i].name.Contains("L_")) { if (Random.Range(0, 5) == 0) { scriptpilote.DisableLeft(); } } if (colliders[i].name.Contains("R_")) { if (Random.Range(0, 5) == 0) { scriptpilote.DisableRight(); } } } TankHealth targethealth = parentTry.GetComponent <TankHealth>(); if (!targethealth) { continue; } //on met 5 dégats par partie du tank qu'on trouve, ce qui permet de scale les dégats targethealth.TakeDamage(5); } m_ExplosionParticles = Instantiate(ExplosionPrefab).GetComponent <ParticleSystem>(); m_ExplosionParticles.transform.position = transform.position; m_ExplosionAudio = m_ExplosionParticles.GetComponent <AudioSource>(); m_ExplosionParticles.Play(); 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 la mine. Destroy(gameObject); } }
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); } }
/// <summary> /// Self destruction /// </summary> public void SelfDestruction() { m_HealthScript.TakeDamage(100.0f); }
private void OnTriggerEnter(Collider other) { if (other.isTrigger) { 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>(); TankHealthHardcoded tankHealthHardcoded = targetRigidbody.GetComponent <TankHealthHardcoded>(); // If there is no TankHealth script attached to the gameobject, go on to the next collider. if (!targetHealth && !tankHealthHardcoded) { continue; } // Calculate the amount of damage the target should take based on it's distance from the shell. float damage = CalculateDamage(targetRigidbody.position); if (!targetHealth) { tankHealthHardcoded.TakeDamage(damage); } else { // 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 shell. Destroy(gameObject); }
// Used to force a stalemate when a round has gone on too long. public void Kill() { m_Health.TakeDamage(Mathf.Infinity); }
private void OnTriggerEnter(Collider other) { Debug.Log("JAI TRIGGER sur " + other.name); // 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); // Go through all the colliders... for (int i = 0; i < colliders.Length; i++) { //Debug.Log("JAI COLLIDE "+colliders[i].name); // ... and find their rigidbody. Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody> (); Rigidbody parentTry = colliders[i].GetComponentInParent <Rigidbody>(); // Si le parent de l'element a pas de rigidbody c'est pas un bout du tank, donc on passe au suivant. if (!parentTry) { continue; } //Debug.Log("je trouve " + parentTry.name+" from "+colliders[i].name); //Si on trouve pas le tag tank, on a rien a faire donc on continue if (parentTry.tag != "Tank") { continue; } //Debug.Log("le tag tank fonctionne"); PilotController scriptpilote = parentTry.GetComponent <PilotController>(); //si y'a pas de script pilote on passe au collider suivant if (scriptpilote) { if (colliders[i].name.Contains("L_")) { if (Random.Range(0, 10) == 0) { scriptpilote.DisableLeft(); } } if (colliders[i].name.Contains("R_")) { if (Random.Range(0, 10) == 0) { scriptpilote.DisableRight(); } } } TankHealth targethealth = parentTry.GetComponent <TankHealth>(); if (!targethealth) { continue; } //on met 5 dégats par partie du tank qu'on trouve, ce qui permet de scale les dégats targethealth.TakeDamage(5); } m_ExplosionParticles = Instantiate(ExplosionPrefab).GetComponent <ParticleSystem>(); m_ExplosionParticles.transform.position = transform.position; m_ExplosionAudio = m_ExplosionParticles.GetComponent <AudioSource>(); m_ExplosionParticles.Play(); 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); }