Question by
AlphaWail · Jun 19, 2017 at 11:16 PM ·
javascriptvariablesparameters
Parameter for animation not updating
Trying to run an animation, but it won't transition because it won't detect the change in the variable. Here is the script I use on my player. The variable is "moving"
#pragma strict
var Front : Sprite;
var Back : Sprite;
var Left : Sprite;
var Right : Sprite;
public var moving : boolean;
public function Update () {
moving = false;
if(Input.GetKey("w")){
moving = true;
transform.Translate(Vector3(0,0.2,0));
GetComponent(SpriteRenderer).sprite = Front;
}
if(Input.GetKey("s")){
transform.Translate(Vector3(0,-0.2,0));
}
if(Input.GetKey("d")){
transform.Translate(Vector3(0.2,0,0));
}
if(Input.GetKey("a")){
transform.Translate(Vector3(-0.2,0,0));
GetComponent(SpriteRenderer).sprite = Left;
}
Debug.Log(moving);
}
Comment