• RuntimesUnity
  • Unity How to Change SkeletonGraphic Change Bone Position

Hello, I am new at Spine. I need to change one of my skeleton's bone to achieve aiming. I reviewed SpineBoy example scene and it seemed easy. But here is a problem. This code only works on SpineAnimation object which is on world. But my object is SkeletonGraphic and it is on Camera Canvas. How can I achieve same functionality with this code?

`public class SpineboyTargetController : MonoBehaviour {

	public SkeletonAnimation skeletonAnimation;

	[SpineBone(dataField: "skeletonAnimation")]
	public string boneName;
	public Camera cam;

	Bone bone;

	void OnValidate () {
		if (skeletonAnimation == null) skeletonAnimation = GetComponent<SkeletonAnimation>();
	}

	void Start () {
		bone = skeletonAnimation.Skeleton.FindBone(boneName);
	}

	void Update () {
		Vector3 mousePosition = Input.mousePosition;
		Vector3 worldMousePosition = cam.ScreenToWorldPoint(mousePosition);
		Vector3 skeletonSpacePoint = skeletonAnimation.transform.InverseTransformPoint(worldMousePosition);
		skeletonSpacePoint.x *= skeletonAnimation.Skeleton.ScaleX;
		skeletonSpacePoint.y *= skeletonAnimation.Skeleton.ScaleY;
		bone.SetLocalPosition(skeletonSpacePoint);
	}
}`

I tried some position convertings but I cannot event move target bone. I want this functionality also works on Canvas SkeletenGraphic object.

  • fefe 回复了此帖
    Related Discussions
    ...

    fefe
    I am trying to control that if bone.SetLocalPosition() is working or not? I used bone.GetLocalPosition() and it gave me -20, 16, 0. Then I manually did bone.SetLocalPosition(new Vector2(0, 0)). When I print bone.GetLocalPosition() after set, it continues to give me the -20, 16, 0 result. But it is working well on SkeletonAnimation. I couldn't get the problem on SkeletonGraphic.

    Hello and welcome to Spine! 🙂

    You are right that adapting the code of SpineboyTargetController to SkeletonGraphic is not trivial in this case. Thus we have just added two example component variants for SkeletonGraphic in this commit. You may mostly be interested in the added SpineboyTargetControllerGraphic example component. Using the SpineboyTargetControllerGraphic and SpineboyBeginnerViewGraphic components instead of the original ones of the example scene should allow you to use SkeletonGraphic instead of SkeletonAnimation.

    New spine-unity 4.1 and 4.2-beta packages are available for download here as usual:
    https://esotericsoftware.com/spine-unity-download

    Thanks for reporting!