unity3d - 如何在游戏中放大布娃娃 - Unity
解决方案
欢迎来到 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];
}
}
}
只需确保仅在需要时进行重新分配,因为它会损害您的表现......
推荐阅读
- windows - 拦截或读取 Windows 推送通知
- html - 如何使用 CSS 为 body 和 boder 设置不同的不透明度?
- css - CSS 关键帧动画名称
- javascript - 需要 JavaScript 才能通过电子邮件传递 URL 地址,该地址将链接到打开特定模式的登录页面
- javascript - 笑话/酶 expect.any(ReactComponent)
- sql - 从 SELECT 语句中导出数据
- google-cloud-platform - 在 BigQuery 目标中导出日志接收器 - Google Cloud Platform
- r - R中的性别检测
- json - 将对象转换为数组
- asp.net-core - 使用 Windows 身份验证的自定义状态代码页