Example #1
0
    IEnumerator Attack()
    {
        while (true)
        {
            yield return(new WaitUntil(() => canAttack));

            yield return(new WaitUntil(() => target != null));

            yield return(new WaitUntil(() => Vector2.Distance(target.transform.position, transform.position) < range));

            animator.SetTrigger(attackTrigger);

            Vector2 direction = target.transform.position - transform.position;

            float angle = Vector2.SignedAngle(Vector2.up, direction);
            if (angle < -157.5f)
            {
                angle *= -1;
            }
            animator.SetFloat(angleFloat, angle);
            photonView.RPC("SetAttackAnimatorTrigger", RpcTarget.Others, angle);

            if (!ranged)
            {
                target.Damage(damage);
            }
            else
            {
                direction.Normalize();
                photonView.RPC("SpawnProjectile", RpcTarget.Others, direction, damage);
                SpawnProjectile(direction, damage);
            }
            yield return(new WaitForSeconds(time));
        }
    }
Example #2
0
    private void MeleeAttack(Vector2 direction)
    {
        Collider2D[] collider2Ds = Physics2D.OverlapCircleAll(attackPivot.position + (Vector3)direction * (distance + 0.3f), radius, layerMask);

        foreach (var col in collider2Ds)
        {
            HealthPoints healthPoints = col.GetComponent <HealthPoints>();
            if (healthPoints != null)
            {
                healthPoints.Damage(PhysicalDamage, gameObject.transform, 0);
            }
        }
    }