Copy one texture from another gameObject

How would you copy one texture from 1 game object to another?

I tried this and it did not work.

GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
plane.renderer.material.mainTexture = GameObject.Find"testObject").render.material.mainTexture;

I get message saying it does not contain a definition for render and no extension method.

I like to get the testObject texture copied to the plane texture via script automatically.

Depends if the shader has a maintexture, to be sure, go to the shader and chech for something like _Mat declared on top. Keep that name in the back of your mind because you can get the texture of a shader with this:

        renderer.material.GetTexture("<texture name>");

this works for normalmaps, diffuse, just any texture the shader asks!

EDIT:

Oh yea, and you can set it with:

        renderer.material.SetTexture("<texture name>", Texture);

This worked

plane.renderer.material.mainTexture = GameObject.Find(“TestObject”).renderer.material.mainTexture;

I tried many version like.

plane.renderer.material.Texture = GameObject.Find("TestObject").renderer.material.Texture;
plane.renderer.material.Texture = GameObject.Find("TestObject").renderer.material.mainTexture, Texture;
planet.Renderer.Material.Texture = GameObject.Find("TestObject").Renderer.Material.Texture;
plane.renderer.material.mainTexture = GameObject.Find"testObject").render.material.mainTexture;

I had no idea I was this close. The answer was this.

plane.renderer.material.mainTexture = GameObject.Find("TestObject").renderer.material.mainTexture;