Exemplo n.º 1
0
    public override void Attack()
    {
        Vector2 dir = moveHandler.GetDirection();

        dir *= attackDistance;
        Debug.DrawLine(moveHandler.transform.position, new Vector2(dir.x + moveHandler.transform.position.x, dir.y + moveHandler.transform.position.y), Color.red);
        Vector2 attackPoint = new Vector2(dir.x + moveHandler.transform.position.x, dir.y + moveHandler.transform.position.y);

        RaycastHit2D [] hits = Physics2D.CircleCastAll(attackPoint, attackDistance / 2, attackPoint);

        foreach (RaycastHit2D hit in hits)
        {
            if (!(hit.collider.name.Equals(moveHandler.name, System.StringComparison.CurrentCulture)) && hit.collider.CompareTag("Character"))
            {
                Debug.Log(hit.collider.name + " : " + moveHandler.name);
                hit.collider.GetComponent <HealthHandler>().Damage(damage);
            }
        }
    }