my character movements are now working but i want to the exchange the animation of the key press “a” and “d” to each other. the “a” has a left movement while the “d” has the right movement…
I want to exchange their animations while im pressing “s”… ![]()
here is my code…
var speed = 10.0;
var rotateSpeed= 1.0;
function Update ()
{
var forward = transform.TransformDirection(Vector3.forward);
var controller : CharacterController =
GetComponent(CharacterController);
//forward movement
var curSpeed = speed * Input.GetAxis (“Vertical”);
controller.SimpleMove(forward * curSpeed);
if(Input.GetKey(“w”))
animation.CrossFade(“run”);
animation[“run”].wrapMode= WrapMode.Loop;
if(Input.GetKeyUp (“w”))
animation.CrossFade (“idle”);
animation[“idle”].wrapMode = WrapMode.Once;
//left movement
transform.Rotate(0, Input.GetAxis (“Horizontal”) * rotateSpeed ,0);
if (Input.GetKey(“a”) )
animation.CrossFade (“left”);
animation[“left”].wrapMode = WrapMode.Loop;
if(Input.GetKeyUp (“a”))
animation.CrossFade (“idle”);
animation[“idle”].wrapMode = WrapMode.Once;
//right movement
if (Input.GetKey(“d”) )
animation.CrossFade (“right”);
animation[“right”].wrapMode = WrapMode.Loop;
if(Input.GetKeyUp (“d”))
animation.CrossFade (“idle”);
animation[“idle”].wrapMode = WrapMode.Once;
//reverse movement
if (Input.GetKey(“s”))
animation.CrossFade(“reverse”);
animation[“reverse”].wrapMode = WrapMode.Loop;
if(Input.GetKeyUp(“s”))
animation.CrossFade(“idle”);
animation[“idle”].wrapMode = WrapMode.Once;
//this the code that im trying to fix for exchanging animation
while (Input.getKey(“s”)){
Input.GetKey(“a”);
animation.CrossFade(“right”);
}