When changing my texture, it shows up blank.

I am using a piece of code to change my texture, but when it changes it can’t seem to find it, instead it shows up white. Here is my code:

private var MainChar : GameObject;
var runspeed = 1;
var MeleeRight : Texture;
var MeleeLeft : Texture;

function Start () {
MainChar = GameObject.Find("MainChar");

}

function Update () {

if (transform.position.x < MainChar.transform.position.x)
transform.Translate(Vector3.forward * runspeed * Time.deltaTime);
renderer.material.mainTexture = MeleeRight;
if (transform.position.x > MainChar.transform.position.x)
transform.Translate(Vector3.forward * runspeed * Time.deltaTime * -1);
renderer.material.mainTexture = MeleeLeft;

}

By the way it is for an enemy AI; that is why there is the MainChar bit - it works fine tho.

Here’s some flaws I’ve noticed in this script you should change:

Change

var MeleeRight : Texture;
var MeleeLeft : Texture;

to

var MeleeRight : Texture2D;
var MeleeLeft : Texture2D;

and

renderer.material.mainTexture = MeleeRight;
renderer.material.mainTexture = MeleeLeft;

to

transform.renderer.material.mainTexture = MeleeRight;
transform.renderer.material.mainTexture = MeleeLeft;

I’m not sure if this will fix it though. It could also be the type of shader on the material. Which shader are you using?