public int Fire(AOESpell definition, GameObject caster, int layer, float multiplier) { var collidedObjects = Physics.OverlapSphere(transform.position, definition.radius); int attackPoints = 0; foreach (var collision in collidedObjects) { var go = collision.gameObject; if (Physics.GetIgnoreLayerCollision(layer, go.layer)) { break; } var attack = definition.CreateAttack(caster.GetComponent <CharacterStats>(), go.GetComponent <CharacterStats>(), multiplier); var attackables = go.GetComponents(typeof(IAttackable)); foreach (var attackable in attackables) { ((IAttackable)attackable).OnAttack(caster, attack); attackPoints += attack.Damage; } } Destroy(gameObject, TimeOnField); return(attackPoints); }
void makeAOE() { animator.speed = 2.0f; AOESpell a = Instantiate(aoespell, transform.position, transform.rotation); a.setPlayerNo(playerNum); AudioManager.instance.PlaySound("AOE", a.transform.position); }
/// <summary> /// We are overriding the characters update function, so that we can execute our own functions /// </summary> protected override void Update() { //Executes the GetInput function GetInput(); ClickToMove(); //Clamps the player inside the tilemap transform.position = new Vector3(Mathf.Clamp(transform.position.x, min.x, max.x), Mathf.Clamp(transform.position.y, min.y, max.y), transform.position.z); if (unusedSpell != null) { Vector3 mouseScreenPostion = mainCam.ScreenToWorldPoint(Input.mousePosition); unusedSpell.transform.position = new Vector3(mouseScreenPostion.x, mouseScreenPostion.y, 0); float distance = Vector2.Distance(transform.position, mainCam.ScreenToWorldPoint(Input.mousePosition)); if (distance >= aoeSpell.MyRange) { unusedSpell.GetComponent <AOESpell>().OutOfRange(); } else { unusedSpell.GetComponent <AOESpell>().InRange(); } if (Input.GetMouseButtonDown(0) && distance <= aoeSpell.MyRange) { AOESpell s = Instantiate(aoeSpell.MySpellPrefab, unusedSpell.transform.position, Quaternion.identity).GetComponent <AOESpell>(); Destroy(unusedSpell); unusedSpell = null; s.Initialize(aoeSpell.MyDamage, aoeSpell.MyDuration); mana.MyCurrentValue -= aoeSpell.ManaCost; } } base.Update(); }