Quickly switch sprite animation

I have a character for a 2D platformer with many different animations, such as idle/running/jumping animations for left and right. These are animations made from a spritesheet (nothing has been done inside of Unity). Currently I’m akwardly switching animation through the Animator window and turning on and off parameters. The problem is that not only the Animator window is very messy, but my script as well. So I’m looking for a better way to switch between animations while using sprite sheet animations. Down below a code preview of how I currently switch between animations:

// Check and set animations for action when facing right. 
		if(player.Horizontal > 0)
		{
			if(player.isGrounded)
			{
				// Running.
				playerAnimator.SetBool("Running_R", true);
				playerAnimator.SetBool("Idle_R", false);
				playerAnimator.SetBool("Jump_R", false);
			}
			else
			{
				// Jumping while running.
				playerAnimator.SetBool("Jump_R", true);
				playerAnimator.SetBool("Running_R", false);
				playerAnimator.SetBool("Idle_R", false);
			}
		}

		if(player.Horizontal == 0)
		{
			if(player.isGrounded)
			{
				// Idle.
				playerAnimator.SetBool("Idle_R", true);
				playerAnimator.SetBool("Running_R", false);
				playerAnimator.SetBool("Jump_R", false);
			}
			else
			{	
				// Jumping while idle.
				playerAnimator.SetBool("Jump_R", true);
				playerAnimator.SetBool("Idle_R", false);
			}
		}

So my question is: How do I switch spritesheet animations more easily and more efficient ?

Rather than using Bools for everything in your animator, you could use Triggers instead. They another parameter type, but they’re more suited for rapid changes in state.

Instead of changing a number of bool for each thing, your code would look something like this:

 // Check and set animations for action when facing right. 
         if(player.Horizontal > 0)
         {
             if(player.isGrounded)
             {
                 // Running.
                 playerAnimator.SetTrigger("Running_R");
             }
             else
             {
                 // Jumping while running.
                 playerAnimator.SetTrigger("Jump_R");
             }
         }
 
         if(player.Horizontal == 0)
         {
             if(player.isGrounded)
             {
                 // Idle.
                 playerAnimator.SetTrigger("Idle_R");
             }
             else
             {    
                 // Jumping while idle.
                 playerAnimator.SetTrigger("Jump_R");
             }
         }

You would have to change a few little things around in your transitions, but it should be cleaner in the long run.

I actually forgot about this question I asked. I did find a solution a while back, but I’ll share it anyway:

using UnityEngine;
using System.Collections;

public class Animation : MonoBehaviour 
{
	public enum animations
	{
		Idle,
		Walk,
		Jump,
		Fall
	}

	public animations currentAnimation;		// Animation that is currently playing.

	public Animator Animator;				// The animator you want to use.

	void Update () 
	{
		if(/* Idle */)
			TransitionTo(animations.Idle, "NameOfIdleAnimation");

		if(/* Moving */)
			TransitionTo(animations.Idle, "NameOfWalkingAnimation");
	}

	// Set the animation enum, Name of the animation you want to play.
	void TransitionTo(animation anim, string name)
	{
		// Check if the animation is already playing or not/
		if (currentAnimation != anim)
		{
			Animator.Play(name);
			currentAnimation = anim;
		}
	}
}

The nice thing about it is that because I use Pixel art graphics I don’t need smooth transitions and this solution doesn’t require a transition in the Animator. Just an Animator with the animations in it (with the right names of course).