Hit animation does not play
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine.Unity;
public class Player : MonoBehaviour
{
public SkeletonAnimation skeletonAnimation;
public AnimationReferenceAsset idle, walk, jump, hit;
public string currentState;
public float speed;
public float movement;
public Rigidbody2D rigidbody;
public Joystick joystick;
public string currentAnimation;
public float jumpSpeed;
public string previousState;
// Start is called before the first frame update
void Start()
{
rigidbody = GetComponent<Rigidbody2D>();
currentState = "Idle";
SetCharacterState(currentState);
}
// Update is called once per frame
void Update()
{
Move();
}
public void SetAnimation(AnimationReferenceAsset animation, bool loop, float timeScale) {
if(animation.name.Equals(currentAnimation)){
return;
}
Spine.TrackEntry animationEntry = skeletonAnimation.state.SetAnimation(0, animation, loop);
animationEntry.TimeScale = timeScale;
animationEntry.Complete += AnimationEntry_Complete;
currentAnimation = animation.name;
}
private void AnimationEntry_Complete(Spine.TrackEntry trackEntry){
Debug.Log("AnimationEntry_Complete");
if(currentState.Equals("jump") || currentState.Equals("hit") ){
SetCharacterState(previousState);
Debug.Log("complete");
}
}
public void SetCharacterState(string state){
if (state.Equals("walk")) {
SetAnimation(walk, true, 2f);
}
else if (state.Equals("hit")) {
SetAnimation(hit, false, 1f);
}
else if (state.Equals("jump")) {
SetAnimation(jump, false, 1f);
} else {
SetAnimation(idle, true, 1f);
}
currentState = state;
}
public void Move() {
movement = joystick.Horizontal;
rigidbody.velocity = new Vector2(movement * speed, rigidbody.velocity.y);
if(movement != 0) {
if (!currentState.Equals("jump")){
SetCharacterState("walk");
}
if (!currentState.Equals("hit")){
SetCharacterState("walk");
}
if (movement > 0) {
transform.localRotation = Quaternion.Euler(0, 0, 0);
} else {
transform.localRotation = Quaternion.Euler(0, 180, 0);
}
}
else {
if (!currentState.Equals("jump")){
SetCharacterState("Idle");
}
if (!currentState.Equals("hit")){
SetCharacterState("Idle");
}
}
}
public void Jump() {
rigidbody.velocity = new Vector2(rigidbody.velocity.x, jumpSpeed);
if (!currentState.Equals("jump")) {
previousState = currentState;
}
SetCharacterState("jump");
}
public void Hit() {
if (!currentState.Equals("hit")) {
previousState = currentState;
}
SetCharacterState("hit");
}
}