![](/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.