Change Unity Physics material via code

Hallo, ich bin neu in Unity und möchte ein Code so programmieren, dass wenn wenn mein Objekt “ladder” berührt, Friction vom PYM2D aktiviert wird. Kann mir jemand helfen und sagen wie ich dies programmmiere?

Hi, I am new to Unity and would like to program a code so that when my object touches “Ladder”, Friction is activated by PYM2D. Can someone help me and tell me how to programme?

public PhysicsMaterial2D PYM2D;
if(collision.gameObject.tag == "ladder")
        {
            ______
        }

You need to apply the PhysicsMaterial2D to the sharedMaterial field of the RigidBody2D.

GetComponent<RigidBody2D>().sharedMaterial = PYM2D;

Ideally you will save a reference to the RigidBody2D in a member variable so that you don’t need to GetComponent every time there is a collision.