void damageNearbyPlayers() { //get items overlapping in the collision circle Collider2D[] colls = Physics2D.OverlapCircleAll(explosive.position, farAreaEffect); //for each item in collision foreach (Collider2D col in colls) { //if it was a tank if (col.CompareTag("Tank") && MenuUI.getFlag() != 1) { Tank tank = col.gameObject.GetComponent <Tank>(); //Get the tank's Tank.cs component. float distance = Vector3.Distance(col.transform.position, explosive.position); //Debug.Log("tank in explosion distance:" + distance); int damage = farDamage; if (distance <= closeAreaEffect) //if tank is in the close to the centre Area { damage = closeDamage; //Debug.Log("close"); } else if (distance <= mediumAreaEffect) //if tank is in the middle Area { damage = mediumDamage; //Debug.Log("medium"); } //aplly damage to the tank tank.Damage(damage); } //if it was a tank in multiplayer mode else if (col.CompareTag("Tank")) { TankMultiplayer tank = col.gameObject.GetComponent <TankMultiplayer>(); //Get the tank's Tank.cs component. float distance = Vector3.Distance(col.transform.position, explosive.position); //Debug.Log("tank in explosion distance:" + distance); int damage = farDamage; if (distance <= closeAreaEffect) //if tank is in the close to the centre Area { damage = closeDamage; //Debug.Log("close"); } else if (distance <= mediumAreaEffect) //if tank is in the middle Area { damage = mediumDamage; //Debug.Log("medium"); } //aplly damage to the tank tank.Damage(damage); } } }
void ProjectileSimple(Collision2D col) { if (col.gameObject.tag == "Tank" && MenuUI.getFlag() != 1) { //Is the object we hit a tank? Tank tank = col.gameObject.GetComponent <Tank>(); //Get the tank's Tank.cs component. if (!game.canDamageOwnTank) { //Can we not damage our own tank? if (tank.id != tankId) //Is the tank we hit not the one that shot this projectile? { tank.Damage(damage); //Call the damage function on that tank to damage it. } } else { tank.Damage(damage); } } else if (col.gameObject.tag == "Tank") {//Is the object we hit a tank? Debug.Log("tankMultiplayer"); TankMultiplayer tank = col.gameObject.GetComponent <TankMultiplayer>(); /*if (!game.canDamageOwnTank) * { //Can we not damage our own tank? * if (tank.id != tankId) * { //Is the tank we hit not the one that shot this projectile? * tank.Damage(damage); //Call the damage function on that tank to damage it. * } * }*/ //else //{ tank.Damage(damage); //} } GameObject hitEffect1 = Instantiate(hitParticleEffect, transform.position, Quaternion.identity) as GameObject; Destroy(hitEffect1, 1.0f); Destroy(gameObject); }