I have this 3D game where you’ll be moving your character via buttons, you’ll stack your commands and will hit a certain button to execute it.
So for example, i’ll hit ‘forward-forward-jump’ it will send 112 on my script and separate them
since my first two commands are 1, i need my character to play “run” animation twice and then jump.
But the problem is when it plays run animation it runs forever…
and when it plays jump it just freezes and doesnt run the next command.
Here’s my code.
private Animator anim;
private bool runToIdle = false;
private bool jumpToIdle = false;
private string moveCount = "";
void Start () {
anim = gameObject.GetComponentInChildren<Animator> ();
}
public void executeAction(){
string[] arr = moveCount.Split ('>');
int[] iarr = new int[arr.Length-1];
for (int i=0; i<arr.Length-1; i++) {
int.TryParse(arr[i],out iarr[i]);
}
StartCoroutine(Move (iarr));
}
public void setAction(int moveKey){
if (moveKey==5) {
executeAction();
} else {
moveCount = string.Concat (moveCount, moveKey.ToString () + ">");
}
}
IEnumerator MoveImplementation(int command){
float t;
if(command==1){
t = 0.5f;
runToIdle = true;
jumpToIdle = false;
} else {
t = 0.9f;
runToIdle = false;
jumpToIdle = true;
}
anim.SetInteger ("IntParameter", command);
yield return new WaitForSeconds (t);
}
IEnumerator Move(int[] iarr){
for (int i=0; i<iarr.Length; i++) {
Debug.Log (iarr[i]);
StartCoroutine(MoveImplementation(iarr[i]));
yield return new WaitForSeconds (0.5f);
}
if(runToIdle){
anim.SetInteger("IntParameter",0);
}
else if(jumpToIdle){
anim.SetInteger("IntParameter",3);
}
}