If you receive crashes, you're doing something wrong.
If you receive a NullReferenceException, likely in OnEnable()
your references like Idleanimator.AnimationState
are not set up yet. If you're using recent spine-unity versions, accessing skeletonAnimation.AnimationState
will initialize it automatically, while on older versions you will need to call skeletonAnimation.Initialize(false);
.
What does the crash say, or what is the exception message saying?
Noticing the lines:
Idleanimator.AnimationState.Start += JumpMethod;
..
attackAnimator.AnimationState.Complete += AttckAnimalComplete;
What is Idleanimator
and what is attackAnimator
? Are they separate SkeletonAnimation
instances? Are you sure that you want to have multiple SkeletonAnimation
objects and not a single one which plays all animations?
Note that you can also register events to a single TrackEntry
after starting or adding an animation
Spine.TrackEntry trackEntry = animationState.SetAnimation(trackIndex, "attack", true);
trackEntry.Start += OnSpineAnimationStart;
(See the documentation here or in English here)