I have a character with BoxCollider2D
and Animator
components. I need to change a physic material's friction dynamically so I use the next function:
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;
}
The problem is that after an execution of this function the walking animation isn't played anymore totally. If I comment two last lines then all works perfectly but the friction doesn't change, just like To be or not to be.
How can I fix this issue?