Unable to access material property of PhysicsMaterial2D dynamically in unity2D

So I have a script that dynamically creates colliders for the edges of the screen.
Now I want to make them bouncy.

I try to do this:

gameObject.GetComponent<Collider2D>().material.bounciness = 1;

but it says UnityEngine has no definition for material.

If I replace the Collider2D with just Collider, the material property is accessible. But since my game is 2D, I need it to work with Collider2D.

How do I do it? If it’s not possible, what are the workarounds?

Collider2D has no property called “material”, but it has a property called “bounciness” (and also a property “sharedMaterial” that is a reference to a PhysicsMaterial2D which also has the property “bounciness”). May be that the bounciness property of Collider2D is a shortcut for sharedMaterial.bounciness, I never tried to use this so I’m not 100% sure.