Animation Halted by else

Hey guys, just wondering if I could get a hand with this snippit of player control code. The farting animation gets cut off by my else statement that jumps to and idling animation. I want the fart animation to override all other animation on the monster. My brain is stuck in the mud on this one.

function PlayerMovement ()
{	
	var gAniObject = GameObject.Find("GuyAnimation");	// Find and define the animation mesh

	if (Input.GetKey("right"))	                                                            // Move Right
	{
		transform.position.x += playerMoveSpeed;	
		gAniObject.animation.Play("GuyWalk");
		WalkingDirection(true);
	}
	else if(Input.GetKey("left"))	                                                        // Move Left
	{
		transform.position.x -= playerMoveSpeed;
		gAniObject.animation.Play("GuyWalk");
		WalkingDirection(false);                                                            // flip model								
	}

	else if (Input.GetKeyUp("space")  Time.time > nextFart  GuiControls.charge >= 1)    //Fart
	{
		nextFart = Time.time + fartRate;                                                    // Fart timer spinning up
		Instantiate (fartPrefab, transform.position, Quaternion.identity);                  // Instantiate fart Object
		audio.PlayOneShot (fartSoundRegular);                                               // Play fart sound	
		GuiControls.charge--;                                                               // Minus charges
		gAniObject.animation.Play("GuyFart");                                               // Fart animation play
	}
	else
	{
		gAniObject.animation.Play("GuyIdle");
	}

}

http://www.artmdk.com/WebPlayer.html

Here is the state of things right now.

Could someone help me on best practices how to make something like this work. I would like to make that animation play and finish.

Hello computer friends. I have been messing with this trying to add in yield coroutine and the animation is still just cut off. Can someone take a look at my noob face code? I wish to become a proficient programmer. :slight_smile:

If you want it to ignore the GuyIdle animation while the GuyFart animation is running, you can add a simple if to your else.

else {
    if (!animation.IsPlaying("GuyFart")) {
        animation.Play("GuyIdle");
    }
}

oh snap! thanks Dman going to test that out asap!!!

That worked perfectly testing if the bitwise not animation playing. Thanks!!! BUT… the idle doesnt play and I do not know how to check if the component is attached. How would I remedy this type of issue?

Sorry New Years and I had a some things to drink while I posted LOL. DONT DRINK AND POST. hahaha

A simplified version of what is says up there is “What does it mean to check if component is attached before using it?”
How is this checking accomplished?