我有一个布娃娃。我想在游戏模式中增加这个布娃娃的规模。但是当我增加比例时,布娃娃的骨头混合在一起并流口水。我怎样才能防止这种情况发生?相关图片如下。 正常比例 3x 比例
问问题
50 次
1 回答
1
欢迎来到 StackOverflow。在 Google 上快速搜索后,我为您找到了答案:http: //answers.unity.com/answers/1556521/view.html
TL;DR:关节仅在开始时计算锚点,但以后永远不会更新。要让它们稍后更新,只需重新分配它们
Transform[] children;
private Vector3[] _connectedAnchor;
private Vector3[] _anchor;
void Start()
{
children = transform.GetComponentsInChildren<Transform>();
_connectedAnchor = new Vector3[children.Length];
_anchor = new Vector3[children.Length];
for (int i = 0; i < children.Length; i++)
{
if (children[i].GetComponent<Joint>() != null)
{
_connectedAnchor[i] = children[i].GetComponent<Joint>().connectedAnchor;
_anchor[i] = children[i].GetComponent<Joint>().anchor;
}
}
}
private void Update()
{
for (int i = 0; i < children.Length; i++)
{
if (children[i].GetComponent<Joint>() != null)
{
children[i].GetComponent<Joint>().connectedAnchor = _connectedAnchor[i];
children[i].GetComponent<Joint>().anchor = _anchor[i];
}
}
}
只需确保仅在需要时进行重新分配,因为它会损害您的表现......
于 2021-08-05T09:21:50.420 回答