moving a collider with a scrolling background

so i have a script that moves the material of my ground

rend.material.mainTextureOffset    = new Vector2 ((Time.time * speed) % 1, 0f);

however this doesn’t move the polygon collider i have attached to it so that it can interact with the player. Is there a way to move the collider so that it move with the material

This isn’t really a Good Idea™, because PolygonCollider2D is tied to geometry, not to texture.

But if you insist, you can manipulate the collider’s .offset field, but keep in mind the poly collider will not “wrap” the way the material does. Plus in order to do it right you will have to manually take into account all scales to bring you from screen texture coordinates to internal world coordinates (what the .offset value is given in).

And further if you want wrapping, just clone the collider (to a different GameObject) offset by its full width to the right, and then you can recycle them in an endless loop.

Again though, I would not recommend this approach as it strikes me as a bit counter-intuitive and fragile to other changes in the scene, such as global scale, texture scales, etc., unless you do it just so.

Do you know of a better way to create a scrolling floor that would allow for the collider to move with the object. I was thinking that maybe using a Sprite instead of a material might work but I’m not sure how I would do it.