Hello. I am new to Unity and am making a 2d pixely platformer. I have a run texture and a stand texture. This is the script I am using for my moving and animations(Changing texture). For some reason, it only works for moving right. Any help would be appreciated!
Script:
var MoveSpeed = 0.1;
var runtexture : Texture;
var standtexture : Texture;
function Update () {
if (Input.GetKey (KeyCode.A)){
transform.Translate(Vector3.right *MoveSpeed);
renderer.material.mainTexture = runtexture;
}else{
renderer.material.mainTexture = standtexture;
}
if (Input.GetKey (KeyCode.D)){
transform.Translate(Vector3.left *MoveSpeed);
renderer.material.mainTexture = runtexture;
}else{
renderer.material.mainTexture = standtexture;
}
}
PS:
If the “A” or “D” key is pressed, I want to switch to the walk texture. If not, I want the stand texture.
JAVASCRIPT