根据父节点计算子节点位置,实现类似挂在父节点下效果,未实现缩放
using UnityEngine; public class Test : MonoBehaviour { public Transform m_Father; public Transform m_Child; Vector3 m_OffestPos; Quaternion m_ChildOriRotation; Quaternion m_FatherOriRotation; void Start () { m_OffestPos = m_Child.position - m_Father.position; m_ChildOriRotation = m_Child.rotation; m_FatherOriRotation = m_Father.rotation; } void Update () { var deltaRotation = m_Father.rotation * Quaternion.Inverse(m_FatherOriRotation); m_Child.position = m_Father.position + deltaRotation * m_OffestPos; m_Child.rotation = deltaRotation * m_ChildOriRotation; } }