// called by animation through the TankController and also calculates the damage that is being in the line of sight and if any enemies are in it. public void SonicBoomAnimTrigger() { float sonicboomRadiusfloat = sonicBoomRange.GetComponent <SphereCollider>().radius; Collider[] colliders = Physics.OverlapSphere(sonicBoomRange.transform.position, sonicboomRadiusfloat); RaycastHit[] hits = Physics.SphereCastAll(sonicBoomRange.transform.position, 3 * sonicboomRadiusfloat, sonicBoomRange.transform.forward, 100 * sonicboomRadiusfloat); foreach (RaycastHit hit in hits) { if (hit.collider.gameObject.transform.parent && hit.collider.gameObject.transform.parent.gameObject != controller.gameObject && !hitOnce) { // if we have a rigid body if (hit.collider && hit.collider.gameObject.GetComponent <Rigidbody>()) { Rigidbody hitBody = hit.collider.gameObject.GetComponent <Rigidbody>(); hitBody.mass /= 5; hitBody.isKinematic = false; hitBody.AddExplosionForce(explosionForceSonicBoom, hit.collider.gameObject.transform.position, sonicboomRadiusfloat, upwardModifier); Instantiate(sonicBoomDamageEffect, hit.collider.gameObject.transform.position, hit.collider.gameObject.transform.rotation); } // if we hit an enemy tank if (hit.collider && (hit.collider.gameObject.tag == "playerTank" || hit.collider.gameObject.tag == "Player")) { RTCTankController hitTank = hit.collider.gameObject.transform.parent.gameObject.GetComponent <RTCTankController>(); Instantiate(sonicBoomDamageEffect, hit.collider.gameObject.transform.position, hit.collider.gameObject.transform.rotation); if (hitTank) { hitTank.TakeDamage(sonicboomDamage, this.gameObject); hitOnce = true; if (ArcadeController.instance && ArcadeController.instance.hasTankDied) { if (levelManagerRef != null) { levelManagerRef.AddKill(levelManagerRef.xpCollected); } } } } if (hit.collider.gameObject.transform.parent && hit.collider.gameObject.transform.parent.gameObject.GetComponent <TargetToDestroy>()) { hit.collider.gameObject.transform.parent.gameObject.GetComponent <TargetToDestroy>().TakeDamage(sonicboomDamage, this.gameObject); } } } hitOnce = false; if (hit.gameObject.transform.parent && hit.gameObject.transform.parent.gameObject.GetComponent <TargetToDestroy>()) { hit.gameObject.transform.parent.gameObject.GetComponent <TargetToDestroy>().TakeDamage(sonicboomDamage, this.gameObject); } }
// called by animation through the TankController and also calculates the damage being done to the tanks in range of the user. public void SwipeAnimTrigger() { float swipeRadiusfloat = swipeRadiusCollider.GetComponent <SphereCollider>().radius; Collider[] colliders = Physics.OverlapSphere(swipeRadiusCollider.transform.position, swipeRadiusfloat); foreach (Collider hit in colliders) //For every collider that my overlapshere hit, do this.. { // if we are not the player if (hit.gameObject.transform.parent && hit.gameObject.transform.parent.gameObject != controller.gameObject && !hitOnce) { // if we have a rigid body if (hit && hit.GetComponent <Rigidbody>()) { Rigidbody hitBody = hit.GetComponent <Rigidbody>(); hitBody.mass /= 5; hitBody.isKinematic = false; hitBody.AddExplosionForce(explosionForceSwipe, swipeRadiusCollider.transform.position, swipeRadiusfloat, upwardModifier); } // if we hit an enemy tank if (hit && (hit.gameObject.tag == "playerTank" || hit.gameObject.tag == "Player")) { RTCTankController hitTank = hit.gameObject.transform.parent.gameObject.GetComponent <RTCTankController>(); if (hitTank) { hitTank.TakeDamage(swipeDamage, this.gameObject); hitOnce = true; if (ArcadeController.instance && ArcadeController.instance.hasTankDied) { if (levelManagerRef != null) { levelManagerRef.AddKill(levelManagerRef.xpCollected); } } } } if (hit.gameObject.transform.parent && hit.gameObject.transform.parent.gameObject.GetComponent <TargetToDestroy>()) { hit.gameObject.transform.parent.gameObject.GetComponent <TargetToDestroy>().TakeDamage(swipeDamage, this.gameObject); } } } hitOnce = false; }