프로그래밍/Unity

유니티 애니메이션 끝난 후 이동

Jaebins 2023. 8. 30. 10:41
반응형
public class Enemy : MonoBehaviour
{
    Animator animator;
    Vector3 movePos;

    void Attack()
    {
        // 애니메이션 끝나면 이동
        if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime > 1.0f)
        {
            transform.position += transform.right * movePos.x + transform.forward * movePos.z;
            movePos = new Vector3(0, 0, 0);
        }
        // 위치 저장
        else if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime > 0.99f)
            // movePos에 자식 프로젝트의 로컬포지션을 저장
            movePos = movePos.x == 0 ? transform.GetChild(0).localPosition : movePos;
    }
}
반응형