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.