Beispiel #1
0
    private IEnumerator AttackAction()
    {
        isOnAttack = true;
        if (attackTarget.transform.position.x > transform.position.x)
        {
            spriteRenderer.flipX = true;
        }
        else
        {
            spriteRenderer.flipX = false;
        }

        float attackTime = 0.4f + 100f / DamageCalculator.GetActualStat(baseSpeed, PokemonStat.Speed, this);


        if (CheckParalysis())
        {
            yield return(new WaitForSeconds(attackTime));

            isOnAttack = false;
            yield break;
        }

        StartCoroutine(CheckCanAttack());

        yield return(new WaitForSeconds(attackTime - 0.6f));

        StopAnimation();
        yield return(new WaitForSeconds(0.2f));

        if (range == 1)
        {
            Vector3 startPosition = transform.position;
            for (float timer = 0f; timer < 0.2f; timer += Time.deltaTime)
            {
                transform.position = Vector3.Lerp(startPosition, attackTarget.transform.position, timer / 0.2f);
                yield return(null);
            }

            audioSource.PlayOneShot(hitSound);
            StartCoroutine(BackToOriginalPosition(0.2f));
        }
        else
        {
            yield return(new WaitForSeconds(0.4f));
        }

        int damage = DamageCalculator.CalculateBasicAttackDamage(this, attackTarget);

        currentPp += 5;
        attackTarget.Hit(damage, this, AttackType.Physical);
        isOnAttack = false;

        StartAnimation();
    }