public override void UseSpell(string _s) { base.UseSpell(_s); // Exit if game paused if (WSB_GameManager.Paused) { return; } // Search for pot in corresponding direction RaycastHit2D _hit = Physics2D.BoxCast(transform.position, collider.size, 0, isRight ? Vector2.right : Vector2.left, range, potLayer); //RaycastHit2D _hit = Physics2D.Raycast(new Vector2(transform.position.x, transform.position.y - (shrinked ? .4f : .8f)), isRight ? Vector2.right : Vector2.left, range, potLayer); if (_hit) { WSB_Pot _pot = _hit.transform.GetComponent <WSB_Pot>(); // Exist if WSB_Pot doesn't exist if (!_pot) { return; } // Switch on the given string to find the corresponding seed to grow if (_s == "Trampoline" && trampolineCharges > 0) { Trampoline(_pot); } else if (_s == "Bridge" && bridgeCharges > 0) { Bridge(_pot); } else if (_s == "Ladder" && ladderCharges > 0) { Ladder(_pot); } else if (_s == "Carnivore" && carnivoreCharges > 0) { Carnivore(_pot); } else { _pot.BreakSeed(); } } }
void Ladder(WSB_Pot _pot) { // Exit if growing a seed isn't possible if (!_pot.GrowSeed("Ladder")) { return; } // Reduce ladder charges and update corresponding UI ladderCharges--; spells.UpdateChargesUI(/*SpellType.Ladder,*/ ladderCharges.ToString()); if (ladderCharges == 0) { spells.UpdateEmptyCharges(/*SpellType.Ladder,*/ 0); } }
void Carnivore(WSB_Pot _pot) { // Exit if growing a seed isn't possible if (!_pot.GrowSeed("Carnivore")) { return; } // Reduce carnivore charges and update corresponding UI carnivoreCharges--; spells.UpdateChargesUI(/*SpellType.Carnivore,*/ carnivoreCharges.ToString()); if (carnivoreCharges == 0) { spells.UpdateEmptyCharges(/*SpellType.Carnivore,*/ 0); } }
void Trampoline(WSB_Pot _pot) { // Exit if growing a seed isn't possible if (!_pot.GrowSeed("Trampoline")) { return; } // Reduce trampoline charges and update corresponding UI trampolineCharges--; spells.UpdateChargesUI(/*SpellType.Trampoline,*/ trampolineCharges.ToString()); if (trampolineCharges == 0) { spells.UpdateEmptyCharges(/*SpellType.Trampoline,*/ 0); } }
void Bridge(WSB_Pot _pot) { // Exit if growing a seed isn't possible if (!_pot.GrowSeed("Bridge")) { return; } // Deploy bridge and gives it the direction it needs to grow _pot.GrownSeed.GetComponent <WSB_Bridge>().StartCoroutine(_pot.GrownSeed.GetComponent <WSB_Bridge>().DeployBridge(transform.position.x < _pot.transform.position.x)); // Reduce bridge charges and update corresponding UI bridgeCharges--; spells.UpdateChargesUI(/*SpellType.Bridge,*/ bridgeCharges.ToString()); if (bridgeCharges == 0) { spells.UpdateEmptyCharges(/*SpellType.Bridge,*/ 0); } }