All the pertinent code is below. I have a bunch of attack animations on a nicely rigged character. What I am trying to do is randomize the animations so that attacking is not so repetitive looking.
So, the issue is this. In PlayAttackSequence, whenever I randomly choose the index of my attack array like this
int i = Random.Range( 0, arrMeleAttacks.Length ); my attack animation gets all wierd and never plays correctly. If I use a hard coded value only, like 0, then it plays just fine. Can someone tell me why I cant get it to work with the random integer?
IEnumerator Start () {
while(true) {
switch(_state) {
case State.Init:
Init();
break;
case State.Setup:
SetUp();
break;
case State.Run:
ActionPicker();
break;
}
yield return null;
}
}
//Within the ActionPicker() is the following
if(_isAttacking)
{
attackTime+=Time.deltaTime;
//Play Current Attack
PlayAttackSequence();
if(attackTime>=TotalAttackTime){
_isAttacking=false;
attackTime=0;
TotalAttackTime = 0;
}
}
//Then finally here is PlayAttackSequence()
void PlayAttackSequence()
{
int i = Random.Range( 0, arrMeleAttacks.Length );
string attackName = arrMeleAttacks[0];
animation[attackName].speed = animation[attackName].length / AttackSpeed;
TotalAttackTime = animation[attackName].length;
animation.CrossFade( attackName, 0.15f);
}