Hello there, and I apologize if this is a newbie question. However, I've spent a better part of today racking my brain and searching Google/the documentation trying to figure this out. I had a look at the sample code/scenes as well but I'm still confused.
Basically, I'm wondering if there's a way that I can swap skeletons through code. I'm making a platformer, and I made two separate skeletons for each direction. However, I always ended up with two of the SkeletonData Asset files (I also could not for the life of me figure out how to actually get just one of said files).
Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine;
using Spine.Unity;
public class PlayerAnimation : MonoBehaviour
{
[Header("Walk")]
public AnimationReferenceAsset walkRight;
public AnimationReferenceAsset walkLeft;
[Header("Run")]
public AnimationReferenceAsset runRight;
public AnimationReferenceAsset runLeft;
[Header("Idle")]
public AnimationReferenceAsset idleRight;
public AnimationReferenceAsset idleLeft;
private SkeletonAnimation skeletonAnimation;
// Use this for initialization
void Awake()
{
skeletonAnimation = GetComponent<SkeletonAnimation>();
}
// Update is called once per frame
void Update()
{
//left movement
if (Input.GetKey(KeyCode.A))
{
skeletonAnimation.AnimationState.SetAnimation(1, walkLeft, true);
}
//right movement
if (Input.GetKey(KeyCode.D))
{
skeletonAnimation.AnimationState.SetAnimation(0, walkRight, true);
}
//left idle
if (Input.GetKeyUp(KeyCode.A))
{
skeletonAnimation.AnimationState.SetAnimation(1, idleLeft, true);
}
//right idle
if (Input.GetKeyUp(KeyCode.D))
{
skeletonAnimation.AnimationState.SetAnimation(0, idleLeft, true);
}
}
}
Right now, the Skeleton Animation component in the inspector says that it's switching between the left and right animations, however my player just kind of leans backwards and doesn't actually switch directions or play the left walk cycle animation, for example. I used Animation Reference Asset since I figured that was a way I could get animations to play from both skeletons, but that obviously didn't quite work out how I'd hoped.
I feel like there's something very obvious I'm missing, but I haven't been able to figure it out. Do I need to use Skeleton Animation Multi? I tried using that, but wasn't able to get it working properly (instead my left and right skeletons just appeared over top of one another and the animations didn't play at all).
Again, sorry for the noob question, but thanks in advance for any assistance. 😃