예제 #1
0
    public IEnumerator Attack()
    {
        animator.SetTrigger("IniatiateCombat");
        combat.StartAttack();

        yield return(new WaitForSeconds(delayAnimation));

        float lerpTime = 0;

        while (lerpTime < 1)
        {
            lerpTime          += Time.deltaTime * (1 / movementDuration);
            transform.position = Vector3.Lerp(defaultLocation, target.position, lerpTime);
            yield return(new WaitForEndOfFrame());
        }

        animator.SetTrigger("Attack");
        combat.ArriveOnTarget();

        bool startAnimationAttack = false;

        while (!startAnimationAttack)
        {
            if (animator.GetCurrentAnimatorStateInfo(0).IsName("Attack"))
            {
                startAnimationAttack = true;
            }
            else
            {
                yield return(new WaitForEndOfFrame());
            }
        }
        combat.StartSlash();
        while (animator.GetCurrentAnimatorStateInfo(0).normalizedTime < 1)
        {
            yield return(new WaitForEndOfFrame());
        }
        animator.SetTrigger("ReturnPosition");

        yield return(new WaitForSeconds(delayAnimation));

        lerpTime = 0;
        while (lerpTime < 1)
        {
            lerpTime          += Time.deltaTime * (1 / returnDuration);
            transform.position = Vector3.Lerp(target.position, defaultLocation, lerpTime);
            yield return(new WaitForEndOfFrame());
        }

        combat.ReturnToPosition();
        animator.SetTrigger("Completed");
    }