I have a sprite, to which I attached a Circle Collider 2D.
And then during runtime, i need to access the Material in this collider and change its friction value.
This works:
transform.Find("Body/Leg").collider2D.sharedMaterial.friction = 5f;
But the problem is, that this changes the friction setting globally for all objects which use this same material.
If it wasn’t a 2D collider, but a normal 3D collider i could simply do:
transform.Find("Body/Leg").collider.material.dynamicFriction = 5;
But the collider2D doesn’t have any material property, (like for example collider2D.material), it only has collider2D.sharedMaterial, and changing that changes the value globally and i need to only change the friction value for that one object instance i’m working with.
I also tried this, but it does nothing:
transform.Find("Body/Leg").renderer.material.SetFloat("Friction", 5f);