애니메이션 명을 공유하는 경우 유니티에서 동시 재생하기

2023. 7. 31. 19:59게임개발

이런 경우는 보통 몬스터 애니메이션의 경우가 많을 것임.

run, atk, die, walk..이런식으로 공통적인 행동(behavior)가 있을 경우 유니티에서 이들을 동시에 체크 할 수 있다. 

 

해당 스크립트를 그냥 바로 끼면 되도록 설정해두었으니 요긴하게 쓰일 것이다. 

     

애니메이션은 none으로 설정 후 유니티 게임 모드를 실행하는 게 좋다. 그래야 애니메이션 끼리 믹싱되는 오해를 막을 수 있다. 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine;
using Spine.Unity;

public class motionscript : MonoBehaviour
{
    private SkeletonAnimation skeletonAnimation;
    // Start is called before the first frame update
    void Start()
    {
        skeletonAnimation = GetComponent<SkeletonAnimation>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Z))
        {
            skeletonAnimation.AnimationState.Start += delegate (TrackEntry trackEntry) {
                Debug.Log(string.Format("track {0} started a new animation.", trackEntry.TrackIndex));
            };

            skeletonAnimation.state.AddAnimation(1, "idle", true, 0);
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            skeletonAnimation.state.AddAnimation(1, "run", true, 0);
        }
        if (Input.GetKeyDown(KeyCode.C))
        {
            skeletonAnimation.state.AddAnimation(1, "atk", true, 0);
        }
        if (Input.GetKeyDown(KeyCode.V))
        {
            skeletonAnimation.state.AddAnimation(1, "die", true, 0);
        }
    }
}

 

 

-----------------------------------

여기사 바꿀건 딱 idle run atk die, 입력할 키코드 ZXCV다. 모션이 더 잇으면 복붙하고 아니면 그냥 두거나 잘라도 된다. 편한대로 하는게 제일.

 

 

        skeletonAnimation.AnimationState.Start += delegate (TrackEntry trackEntry) {
                Debug.Log(string.Format("track {0} started a new animation.", trackEntry.TrackIndex));
            };

의 경우에는 해당 애니메이션을 완전히 재생하고(끝 프레임까지 재생하고)다음 애니메이션으로 넘어간다는 의미다. 걸리적 거리면 그냥 없애도 된다.