Complete Noob question-Random numbers don't work

I can’t get this code to work. What I want to happen is that the warrior character cycles through his idle animation, then randomly does either the block or attack animations, then resume the cycle animation. This works with just the block animation but not with the attack animation code added.

function Update () {
	if(!animation.isPlaying){
	animation.CrossFade("Idle1");	
	}	

if(Random.value >.09){
	animation.CrossFade("Thrust1");
	animation.wrapMode = WrapMode.Once;
}
if(Random.value <.01){
	animation.CrossFade("Block_1");
	animation.wrapMode = WrapMode.Once;
}
			
}

First off, you’d be better off trapping one random value then using that in both of your if statements. In each case you generate a different random number instead of creating one that is shared. My guess is that because your block value is looking for such a “small” number it’s just not getting triggered ever.

Example:

function Update () {
  if(!animation.isPlaying){
    animation.CrossFade("Idle1");   
  }   

  var tValue = Random.value;
  if(tValue >.09){
    animation.CrossFade("Thrust1");
    animation.wrapMode = WrapMode.Once;
  }
  if(tValue <.01){
    animation.CrossFade("Block_1");
    animation.wrapMode = WrapMode.Once;
  }
}

Something like that.

If/when you double-post like this (two identical threads in the same or different forums) then please get in touch with a moderator (like me) to nuke one of them.

This thread is now locked, see your other thread for ongoing discussion.