How to create a cloth Gameobject in C#

I’m wondering how to create on the fly a Cloth type Gameobject using C# code and then assign to it a texture, like I can do - for example - with primitives types:

tmp = GameObject.CreatePrimitive(PrimitiveType.Cube);
tmp.renderer.material.mainTexture = my_custom_ texture;

As a newbie I’m stuck with it and I can’t figure out how to do it. Is it possible?

Any help will be very appreciated.

Thanks in advance.

You could create an entirely new cloth object with Cloth myCloth = new Cloth(); or you could create a cloth prefab and instantiate it at runtime where needed.