![](/img/trans.png)
[英]Unity - The Animator won't let not me and not the code to disable a collider. Why?
[英]If disable/enable collider the animator doesn't work anymore
我有一个带有BoxCollider2D
和Animator
组件的角色。 我需要动态改变物理材料的摩擦力,所以我使用下一个函数:
private void ChangeFriction(float friction)
{
boxCollider.sharedMaterial.friction = friction;
boxCollider.enabled = false; // The friction won't be changed if I won't reset the collider
boxCollider.enabled = true;
}
问题是在执行此函数后,步行动画不再完全播放。 如果我评论最后两行,那么一切都完美无缺,但摩擦不会改变,就像To be or not to be 一样。
我该如何解决这个问题?
我一直在使用这段代码来访问摩擦并对其进行更改,它无需启用和禁用对撞机即可工作。 我也可以在编辑器中看到它的变化。
private Collider2D col;
void Start () {
col = gameObject.GetComponent<Collider2D>();
}
void Update () {
if(Input.GetKeyDown(KeyCode.Mouse0))
{
col.sharedMaterial.friction = 1;
}
if (Input.GetKeyDown(KeyCode.Mouse1))
{
col.sharedMaterial.friction = 0.5f;
}
Debug.Log(col.sharedMaterial.friction);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.