- Home /
Secound Animator.GetCurrentAnimatorStateInfo(0).IsName() doesn't work in if Statement
I've been trying to figure out why this problem is happening for a while now but I just can't.
Basically I've set up a laser beam script with a if statement saying that if a certain animation isn't playing then don't fire the laser beam. This is of course so the laser beam fires on the correct animation. I've done it like this:
if(!anim.GetCurrentAnimatorStateInfo(0).IsName("LaserBeam") && !laserBeaming)
{
transform.position = new Vector3(transform.position.x + 3.5f * Time.deltaTime, transform.position.y, transform.position.z);
return;
}
With the laser beam script below it.
I recently added a angry mode for the enemy I'm using this script on and I want the enemy to do the same attacks but at different speeds. I have different animations for when the enemy is angry though with one of the animations being "Angry-LaserBeam" which is basically the same animation as "LaserBeam". I only want the laser beam to fire when the enemy is angry if the "Angry-LaserBeam" animation is playing.
This is the if statement now:
if(!anim.GetCurrentAnimatorStateInfo(0).IsName("LaserBeam") && !laserBeaming || !anim.GetCurrentAnimatorStateInfo(0).IsName("Angry-LaserBeam") && !LaserBeam)
{
transform.position = new Vector3(transform.position.x + 3.5f * Time.deltaTime, transform.position.y, transform.position.z);
return;
}
The problem I am having is if i have that line: "!anim.GetCurrentAnimatorStateInfo(0).IsName("Angry-LaserBeam")" in the if statement then it will never run the code below it, even if the animation "Angry-LaserBeam" is playing. Neither will the laser beam script run even if the animation is just "LaserBeam" when the enemy isn't angry if that line is in the if statement.
I just can't figure out why it's doing this and it has to be that line as if i remove it, the laser beam script works. It also works if I just have "!anim.GetCurrentAnimatorStateInfo(0).IsName("Angry-LaserBeam")" instead of "!anim.GetCurrentAnimatorStateInfo(0).IsName("LaserBeam")" so I've most likely done the "or - ||" part wrong.
Does anyone know what's going on?