Here's assuming you are using SkeletonAnimation:
SkeletonAnimation derives from the SkeletonRenderer class.
This class holds a reference to a Spine.Skeleton
object in skeletonAnimation.skeleton
. This represents an instance of what you rigged and animated in Spine editor.
The skeleton has a collection of Spine.Bone
s, you can find the bone you want with skeleton.FindBone("your bone name")
Each Spine.Bone
object has local position, rotation and scale values: x
, y
, rotation
, scaleX
, scaleY
.
These values are directly manipulated by the runtime when an animation playing, but you can override them if you change the values AFTER the animation is applied.
You can do this by subscribing to the UpdateLocal
event of SkeletonAnimation.
[Spine.Unity.SpineBone] // allows you to have a dropdown if your script is attached to the same GameObject as the SkeletonAnimation
public string myBoneName;
Spine.Bone myBone;
void Start ()
{
var skeletonAnimation = this.GetComponent<SkeletonAnimation>();
Spine.Skeleton skeleton = skeletonAnimation.Skeleton;
myBone = skeleton.FindBone("MyBone");
skeletonAnimation.UpdateLocal += this.UpdateBones;
}
void UpdateBones (ISkeletonAnimation s)
{
myBone.Rotation = 90f; // local rotation in degrees, where rotation 0 points along the x axis.
}
Note that you can shorten the class identifiers if you add using Spine
and using Spine.Unity
to the top of your script.
If you are using Spine PRO to animate, you have less math to figure out in code if you use IK constraints.