Exemple #1
0
    IEnumerator DoAttack2()
    {
        canDoHit2 = false;
        anim.SetTrigger("Attack2");
        hit2candamage = false;
        bool hasHit = false;

        hit2finished = false;

        float timeSinceStart = 0;

        while (!hit2finished)
        {
            timeSinceStart += Time.unscaledDeltaTime;
            isAttacking     = true;

            CheckSwordCollider swordColl = sword.GetComponent <CheckSwordCollider>();
            if (swordColl.hasHitEnemy && !hasHit && swordColl.enemy != null && hit2candamage)
            {
                swordColl.enemy.GetComponent <Enemy>().TakeDamage(damage);
                hasHit = true;
            }

            yield return(false);
        }

        anim.ResetTrigger("Attack2");
        isAttacking = false;
    }
Exemple #2
0
    IEnumerator DoAttack1()
    {
        hit1finished   = false;
        hit1candamage  = true;
        timeSinceStart = 0;
        canDoHit2      = false;
        bool hasHit = false;

        anim.SetTrigger("Attack1");

        while (!hit1finished)
        {
            isAttacking = true;

            CheckSwordCollider swordColl = sword.GetComponent <CheckSwordCollider>();
            if (swordColl.hasHitEnemy && !hasHit && swordColl.enemy != null && hit1candamage)
            {
                swordColl.enemy.GetComponent <Enemy>().TakeDamage(damage);
                print("hit with hit 1");
                hasHit = true;
            }

            if (Input.GetButtonDown("Fire1"))
            {
                if (canDoHit2)
                {
                    StartCoroutine(DoAttack2());
                    yield break;
                }
            }

            yield return(false);
        }

        anim.ResetTrigger("Attack1");
        anim.ResetTrigger("Attack2");

        isAttacking = false;
    }