//****************************************************************************************************************************** // // FUNCTIONS // //****************************************************************************************************************************** //////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Called when the player presses a button on the selection wheel with this world object linked to the button. /// </summary> /// <param name="buildingSlot"> // The building slot that instigated the selection wheel. // (EG: If you're making a building, this is the building slot thats being used.) /// </param> public override void OnWheelSelect(BuildingSlot buildingSlot) { base.OnWheelSelect(buildingSlot); // Detonate all known mines on the attached minefield MineField mineField = buildingSlot.GetBuildingOnSlot() as MineField; for (int i = 0; i < mineField.GetUndetonatedMines().Count; i++) { Mine mine = mineField.GetUndetonatedMines()[i]; mine.DetonateMine(); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Detonates the mine and damages any enemies within the blast radius. /// </summary> public void DetonateMine() { /* * // DEBUGGING SPHERECAST * // Uncomment LINE 273 (the ignore raycast line) otherwise this will give unintended results! * GameObject child = new GameObject(); * child.transform.parent = gameObject.transform; * SphereCollider debug = child.AddComponent<SphereCollider>(); * debug.radius = ExplosionRadius; * debug.isTrigger = true; * debug.transform.localPosition = new Vector3(0, 0, 0); * child.layer = LayerMask.NameToLayer("Ignore Raycast"); */ // Use a spherical raycast for an AOE damage with falloff RaycastHit[] hits = Physics.SphereCastAll(transform.position, ExplosionRadius, transform.forward, 0f); foreach (var rayHit in hits) { WorldObject worldObj = rayHit.transform.gameObject.GetComponentInParent <WorldObject>(); if (worldObj != null) { // Friendly fire is OFF if (worldObj.Team != _Team) { // Determine damage falloff float distanceFromEpicenter = Vector3.Distance(transform.position, rayHit.point); float damageMultiplier = (distanceFromEpicenter / ExplosionRadius) * DamageFalloff; // Damage the object worldObj.Damage(Mathf.FloorToInt(Damages.DamageDefault * damageMultiplier)); } } } // Play OnDeath effect if (ExplosionEffect != null) { // Play ParticleSystem effect = ObjectPooling.Spawn(ExplosionEffect.gameObject, transform.position, transform.rotation).GetComponent <ParticleSystem>(); effect.Play(); // Despawn particle system once it has finished its cycle float effectDuration = effect.duration + effect.startLifetime; StartCoroutine(ParticleDespawn(effect, effectDuration)); } // Remove mine from its attached minefield if (_MineFieldAttached != null) { _MineFieldAttached.GetUndetonatedMines().Remove(this); // Check if the minefield object should be despawned aswell if (_MineFieldAttached.GetUndetonatedMines().Count == 0) { _MineFieldAttached.OnDeath(null); } // Despawn mine ObjectPooling.Despawn(gameObject); } }