How to: Create shader and copy texture?

Hello,

My gameObject has a VertexLit Shader, but I want to switch to a Mobile Unlit Shader, with code. I tried this:

var MOBILEUNLIT : Shader = Shader.Find("Mobile/Unlit");
var TEXTUREIMAGE:Texture=renderer.material.mainTexture;
renderer.material.shader = MOBILEUNLIT;
renderer.material.mainTexture=TEXTUREIMAGE;

As you can see I am attempting to preserve the image in the Base (RGB) texture.

However, the object turns pink? What am I doing wrong?

Thank you kindly for any help.

EDIT: got it to work like this thanks to Professor Snake:

var TEXTUREIMAGE:Texture=SOME_GAME_OBJECT.renderer.material.mainTexture;
var MOBILEUNLIT:Material = new Material (Shader.Find("Mobile/Unlit (Supports Lightmap)"));
MOBILEUNLIT.mainTexture=TEXTUREIMAGE;
SOME_GAME_OBJECT.renderer.material=MOBILEUNLIT;

You can instead have two materials and copy the properties between them.

var vertexLitMaterial:Material=renderer.material;
var unlitMaterial:Material;

unlitMaterial.mainTexture=vertexLitMaterial.mainTexture;
renderer.material=unlitMaterial;

Thank you Professor Snake, you pointed me into the right direction.

I got it to work like this:

var TEXTUREIMAGE:Texture=SOME_GAME_OBJECT.renderer.material.mainTexture;
var MOBILEUNLIT:Material = new Material (Shader.Find("Mobile/Unlit (Supports Lightmap)"));
MOBILEUNLIT.mainTexture=TEXTUREIMAGE;
SOME_GAME_OBJECT.renderer.material=MOBILEUNLIT;

I am using this to switch all materials to more Mobile friendly materials runtime, mainly because it seems IOS is really good at choking on everything.