public override void Attack(Direction direction, VisualCharacter visualCharacter) { Debug.Log("Healing..."); if (visualCharacter.m_Character.ApplyManapoints(-m_ManaConsumption)) { //Calculate the range based on the size of the character Vector2 range = new Vector2(visualCharacter.GetComponent <BoxCollider2D>().size.x + m_Range, visualCharacter.GetComponent <BoxCollider2D>().size.y + m_Range); Collider2D[] colliders = Physics2D.OverlapCapsuleAll(visualCharacter.transform.position, range, CapsuleDirection2D.Vertical, 0f); foreach (var collider in colliders) { if (collider != visualCharacter.GetComponent <Collider2D>() && collider.tag == "Character" && collider.gameObject.layer == GameManager.m_PlayerLayer) { //Get character VisualCharacter character = collider.GetComponent <VisualCharacter>(); if (character) { character.m_Character.ApplyHealthpoints(m_HealAmount); } } } } }
private void Update() { if (!_Character) { _Character = GetComponent <VisualCharacter>(); } if (_CurrentTargetIndex >= m_PatrolPoints.Count) { return; } //Get direction if (Vector3.Distance(m_PatrolPoints[_CurrentTargetIndex], transform.position) > m_Distance) { var direction = m_PatrolPoints[_CurrentTargetIndex] - this.transform.position; direction.Normalize(); direction *= _Speed; _RigidBody2D.velocity = direction; } else { _CurrentTargetIndex++; if (_CurrentTargetIndex >= GameManager.m_Instance.m_CharacterManager.m_Enemies.Count) { _CurrentTargetIndex = 0; } } _Character.m_Character.m_CurrentWeaponTimer += Time.deltaTime; if (_Character.m_Character.m_CurrentWeaponTimer >= _Character.m_Character.m_CharacterStats.m_UnarmedRateOfAttack) { //Check if something is ine attack range Vector2 range = new Vector2(_Character.GetComponent <BoxCollider2D>().size.x + _Character.m_Character.m_CharacterStats.m_UnarmedRange, _Character.GetComponent <BoxCollider2D>().size.y + _Character.m_Character.m_CharacterStats.m_UnarmedRange); Collider2D[] colliders = Physics2D.OverlapCapsuleAll(this.transform.position, range, CapsuleDirection2D.Vertical, 0); foreach (var collider in colliders) { if (collider.tag == "Character" && collider.gameObject.layer == GameManager.m_PlayerLayer) { _Character.m_Character.Attack(Direction.Left); _Character.m_Character.m_CurrentWeaponTimer = 0; return; } } } }
private void OnTriggerEnter2D(Collider2D other) { Collider2D ownerCollider = _OwningCharacter.GetComponent <Collider2D>(); if (ownerCollider && other != ownerCollider && other.tag == "Character" && other.gameObject.layer != GameManager.m_PlayerLayer) { int damage = _OwningCharacter.m_Character.m_CharacterStats.m_Attack + _OwningBow.m_ExtraDamage; _OwningCharacter.m_Character.ApplyHealthpoints(-damage); Destroy(gameObject); } }