using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine;
namespace PLAGame.Client
{
public class FollowSpine : MonoBehaviour
{
public Transform spine;//lua给值
Bone bone;
Transform thisTran;
Vector3 lp=Vector3.zero;
public Transform parentTR;
public string boneName = "bone";//具体跟随的节点可使用脚本的SkeletonAnimation的按钮Add Skeleton Utility,生成实际的骨骼节点 ,角色动的时候,实际的跟随节点
// Start is called before the first frame update
void Start()
{
thisTran = transform;
}
// Update is called once per frame
void FixedUpdate()
{
if (bone != null)
{
bone = spine.GetComponent<SkeletonAnimation>().skeleton.FindBone(boneName);//这部非常重要 必须要重新获得
thisTran.SetParent(spine.transform);
//if (thisTran.localPosition.x != bone.WorldX || thisTran.localPosition.y != bone.WorldY) //有这个会有问题
{
lp.x = bone.WorldX; lp.y = bone.WorldY ;
thisTran.localPosition = lp;
}
thisTran.SetParent( parentTR);
if (Input.GetKeyDown(KeyCode.Space))
{
print(bone.WorldY);
}
}
else
{
bone = spine.GetComponent<SkeletonAnimation>().skeleton.FindBone(boneName);
if (bone == null)
{
print("?? 占不到角色骨骼点");
}
}
}
}
}