• Unity
  • I tried to move the character using the Foot Soldier Exemple

Hi.

I tried to move the character using the Foot Soldier Exemple script.

I want to add a jump animation, but it's difficult because I don't know the code.

Can someone please add some code to jump to?

I wonder if it is possible without using a Rigidbody.
:grinfake

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

namespace Spine.Unity.Examples {
   public class FootSoldierExample : MonoBehaviour {
      [SpineAnimation]
      public string idleAnimation;

  [SpineAnimation]
  public string attackAnimation;

  [SpineAnimation]
  public string moveAnimation;
    
    [SpineAnimation]
    public string jumpAnimation;

    [SpineSlot]
  public string eyesSlot;

  [SpineAttachment(currentSkinOnly: true, slotField: "eyesSlot")]
  public string eyesOpenAttachment;

  [SpineAttachment(currentSkinOnly: true, slotField: "eyesSlot")]
  public string blinkAttachment;

  [Range(0, 0.2f)]
  public float blinkDuration = 0.05f;

  public KeyCode attackKey = KeyCode.Mouse0;
  public KeyCode rightKey = KeyCode.D;
  public KeyCode leftKey = KeyCode.A;
    public KeyCode jumpKey = KeyCode.Space;

    public float moveSpeed = 3;

  SkeletonAnimation skeletonAnimation;

  void Awake () {
     skeletonAnimation = GetComponent<SkeletonAnimation>();
     skeletonAnimation.OnRebuild += Apply;
  }

  void Apply (SkeletonRenderer skeletonRenderer) {
     StartCoroutine(Blink());
  }

  void Update () {
     if (Input.GetKey(attackKey)) {
        skeletonAnimation.AnimationName = attackAnimation;
           
            } else {
        if (Input.GetKey(rightKey)) {
           skeletonAnimation.AnimationName = moveAnimation;
           skeletonAnimation.Skeleton.ScaleX = 1;
           transform.Translate(moveSpeed * Time.deltaTime, 0, 0);
        } else if(Input.GetKey(leftKey)) {
           skeletonAnimation.AnimationName = moveAnimation;
           skeletonAnimation.Skeleton.ScaleX = -1;
           transform.Translate(-moveSpeed * Time.deltaTime, 0, 0);
        } else {
           skeletonAnimation.AnimationName = idleAnimation;
        }
     }
  }

  IEnumerator Blink() {
     while (true) {
        yield return new WaitForSeconds(Random.Range(0.25f, 3f));
        skeletonAnimation.Skeleton.SetAttachment(eyesSlot, blinkAttachment);
        yield return new WaitForSeconds(blinkDuration);
        skeletonAnimation.Skeleton.SetAttachment(eyesSlot, eyesOpenAttachment);
     }
  }
   }
}
Related Discussions
...
7 giorni dopo

Hello, I'm sorry that your post wasn't answered sooner. I'll ask Harri, our resident Unity expert, tomorrow for input and see what we can help you come up with.

Please note that the many Spine example scenes are there for users to examine and learn how the spine-unity runtime and it's API can be used to achieve certain common goals. They are intended as a supplement to the documentation pages here:
spine-unity Runtime Documentation
API Reference - Spine Runtimes Guide

If you are not a programmer and don't understand what the example code means, it is not recommended to base your game on them. In general you will have a hard time in Unity without either learning the basic programming skills that are required, or having a programmer join your project and take over this work. You could perhaps get away with using visual programming tools like PlayMaker (available on the Unity Asset Store), but such visual scripting tools come with the additional problem that they get outdated quickly (target an old spine-unity version), don't provide the whole feature set and the like.

You could also try to purchase some game asset packs which provide some functionality, like the spine-unity asset packs here: Spine: Asset Packs.
This way you could theoretically get away with only replacing existing animations and attachment images with your own ones. However, if you can't read the code or understanding the skeleton setup in Spine, you will have a hard time extending or changing the existing setup in terms of gameplay.

The best way would be to learn some basic programming skills (in C# if you are using Unity) and getting familiar with how things can be done in Unity. It may be some work at first, but will be a very rewarding time investment, which opens up a whole new world of opportunities.

Can someone please add some code to jump to? I wonder if it is possible without using a Rigidbody.

Please always at least post some code that you tried to write yourself which did not work as expected. If you only post a question like "can somebody please do this work for me", it will not encourage others to help. I'm afraid to say that we don't have the time to write your game code for you. Even if we did, it would get you just one step further, but you need to learn to walk yourself, or have someone who takes over programming for you.

In general if you want to setup your game in Unity yourself, you need to familiarize yourself with Unity first and how a game can be set up, how user input can let the player move and how objects can interact in a world with each other. It helps to create a very simple game where e.g. you let a cube jump and move around. It is important to understand what a Rigidbody is for, and how it interacts with a scene, and what you can do with it. It may be tempting to skip learning to walk and trying to run first, but unfortunately it will be painful and not get you very far.

Please note that this is not intended to be discouraging, instead please note that learning some basic programming skills can help you a lot in understanding existing code, and you will get better and better by trying out things yourself.

thank you. harald

Unfortunately, the programmers of our project are not very interested in spine.

This is a sad situation.

Hand over the spine animation file to the programmers.
Request the animation sent by the game to work properly.
But they give unsatisfactory feedback.

They don't even think about researching and developing Spine. The situation is sad. But I understand them. They have a lot of work and no time.

And many projects in our country are likely to be in a similar situation.

So I was testing this and that while studying Unity myself.

And I'm also making tutorials on YouTube so that animators who have the same experience do not have the same experience.



There was a story like this before.

When creating a spine animation and placing this object in the middle, the draw order (order in layer) was not properly expressed.

The programmer also doesn't know how to solve the problem, so he asks to split the object in two.

I'm a spine animator and have only studied spine animation, so I had to export the object in two to solve the problem.

However, there was a renderseparate in the Unity example, which solved the problem very easily. At that time, I thought, 'I must study.'

So I am studying on my own.



I guess I thought writing coding was easy.

I agree that no one will modify the script.

Learning to code is very difficult. I have a Visual Script balt.

It looks like something worth trying out.

Thank you for your always kind reply. Harald's answer helps me a lot.

The text was translated by Google Translator, so the text may be strange. Please understand.

I just noticed that you are the same person who has posted on this forum thread:
I need an educational video
It's terrible that your programmers don't do their part of the work by integrating your animations in Unity, and that you as an animator need to learn programming now. :wounded:

I guess I thought writing coding was easy.

No, unfortunately it's not easy. However, learning to write and adjust scipts in one programming language on your own will get you very far already. The important part is learning the basic mindset of how things are done, learning to read other people's code, how to debug your code when it doesn't work as expected, how to use a debugger (or printf-debugging, if a debugger is not available) and so on.

The text was translated by Google Translator, so the text may be strange. Please understand.

No worries, thanks for posting the translated text. And thanks for your kind words.