After many fruitless hours, I finally got to the end of the tunnel on this code. Hope you enjoy!
Essentially, what this code does is help you in locating a bone from your animation, and then having a GameObject follow that bone. Note that the "bone" in my test is actually just a regular point bone (like the root bone) with NO rotations. I bet rotation might throw this code outta whack but for now, it should do well enough for basic stuff.
Example: The tip of the fishing rod is a GameObject with a Line Renderer. As the bone moves, the referenced GameObject moves along with it. In Spine, the tip of the rod has a single point bone.
Loading Image
Edit: Script should be attached to your animated skeleton game object, hence the "tk2dSpineSkeleton" requirement
//Setup Namespaces
using UnityEngine;
using Spine;
using System.Collections;
//Requires the tk2dSpineSkeleton 'cause that's what we are using bro
[RequireComponent(typeof(tk2dSpineSkeleton))]
public class myBoneFollower: MonoBehaviour {
//Grab our skeleton from the SpineSkeleton script
private tk2dSpineSkeleton skeleton;
//Setting up the variable for our first bone. Giggle.
private Bone myBone;
//Gonna attach our empty GameObject all it's goodies.
//Don't forget to click+drag in Unity, or you can grab it through code
//And a temporary variable for position data
public GameObject myCoolEmpty;
private Vector3 tempPos;
void Start(){
//This is where we grab our skeleton. Get over here.
skeleton = GetComponent<tk2dSpineSkeleton>();
//Now that we have our skeleton, let's grab our wanted bone.
//Change what's in the quotes to find your bone
myBone = skeleton.skeleton.FindBone("bone1");
}
void Update(){
//Let's update myCoolEmpty to follow allow with our animation
//C# is stupid and doesn't let us modify single properties,
//hence all the temp stuff
tempPos = myCoolEmpty.transform.position;
//Spine and/or TK2D don't account for internal Unity scaling and positioning
//SO LET'S MAKE IT ACCOUNT FOR IT
tempPos.x = (myBone.X * transform.localScale.x) + transform.position.x;
tempPos.y = (myBone.Y * transform.localScale.y) + transform.position.y;
myCoolEmpty.transform.position = tempPos;
}
}