• Unity
  • how to multiple animation?

  • Изменено
Related Discussions
...

hello.
I have a question. 🙂

Import my spine data into Unity, assign animations and play them.

Then only one animation will play.

I want to do this.

'Idle animation 1 (1 second) {only character animation}
Idle animation 2 (2 Seconds) {only Background animation}

I want to see the combined (animation 1 character ani + 2 bg ani) value in the game window of Unity.'

But in Unity, i will only see the single selected animation.

I ripped through the raptor cs, but I'm dizzy because I can't see the code.

I just want animations 1 and 2 to play simultaneously.

How to play multiple animations simultaneously in Unity without writing any code? :think:

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

namespace Spine.Unity.Examples
{
    public class Raptor : MonoBehaviour
    {

    #region Inspector
    public AnimationReferenceAsset walk;
    public AnimationReferenceAsset gungrab;
    public AnimationReferenceAsset gunkeep;
    #endregion

    SkeletonAnimation skeletonAnimation;

    void Start()
    {
        skeletonAnimation = GetComponent<SkeletonAnimation>();
        StartCoroutine(GunGrabRoutine());
    }

    IEnumerator GunGrabRoutine()
    {
        // Play the walk animation on track 0.
        skeletonAnimation.AnimationState.SetAnimation(0, walk, true);

        // Repeatedly play the gungrab and gunkeep animation on track 1.
        while (true)
        {
            yield return new WaitForSeconds(Random.Range(0.0f, 0f));
            skeletonAnimation.AnimationState.SetAnimation(1, gungrab, true);

            yield return new WaitForSeconds(Random.Range(0.5f, 3f));
            skeletonAnimation.AnimationState.SetAnimation(1, gunkeep, false);
        }

    }

}
}

By modifying the raptor cs code like this, Idle 1 and Idle 2 simultaneous playback was successful.

Would it be okay to do this? :grinteeth:


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

namespace Spine.Unity.Examples {
   public class Raptor : MonoBehaviour {

  #region Inspector
  public AnimationReferenceAsset walk;
  public AnimationReferenceAsset gungrab;
  #endregion

  SkeletonAnimation skeletonAnimation;

  void Start () {
     skeletonAnimation = GetComponent<SkeletonAnimation>();
     StartCoroutine(GunGrabRoutine());
  }

  IEnumerator GunGrabRoutine () {
        // Play the walk animation on track 0.
        skeletonAnimation.AnimationState.SetAnimation(0, walk, true);
        skeletonAnimation.AnimationState.SetAnimation(1, gungrab, true);

        yield break;
    
  }

   }
}

This is how I confirmed that it was playing. 😃

I'm not 100% sure I correctly understand what you are trying to achieve. If you want to set a second initial animation on another AnimationState track, then currently there are no Inspector components available to do so, you need to write your own script component that does this. We have an issue ticket here to support setting the initial animation on other tracks, but unfortunately we didn't get to this yet:
https://github.com/EsotericSoftware/spine-runtimes/issues/1629

Please note that you could simplify your code a bit (it needs no coroutine):

#region Inspector
public AnimationReferenceAsset animation0;
public AnimationReferenceAsset animation1;
#endregion

void Start () {
    skeletonAnimation = GetComponent<SkeletonAnimation>();
    SetInitialAnimations();
}

void SetInitialAnimations () {
    skeletonAnimation.AnimationState.SetAnimation(0, animation0, true);
    skeletonAnimation.AnimationState.SetAnimation(1, animation1, true);
}

You could also use the Animation Name Inspector property of the SkeletonAnimation component for the animation on track 0 and only set animations on additional higher tracks via your component.