How to stop animation from looping ?

Yes I unsticked loop under animation, but nothing happens, it’ still looping.

I am trying to slide with character, but animation goes to slide then to run and so on. How do I stop this ? Here is my script.

using UnityEngine;
using System.Collections;

public class SlideScript : MonoBehaviour {

    Animator slide;






    // Use this for initialization
    void Start () {
        slide = GetComponent<Animator>();
   



    }
   
    // Update is called once per frame
    void Update () {

        if (Input.GetKeyDown (KeyCode.S)) {
            slide.SetTrigger ("Slide");
        } 


    }

}

Anyone ?

How does your animation state machine look?

What exactly do you mean, I am new to Unity, so I don’t know what you mean exactly ? Could you explain more “machine look” ?

I mean a picture of this:

Here it is

Did you try something like that:

  if (Input.GetKeyDown (KeyCode.S)) {
    slide.SetTrigger ("Slide");
  } else {
    slide.ResetTrigger ("Slide");
  }
1 Like

Nothing happens when I try this.

Here is my JumpScript, and it’s where most of my code is stored, you can take a look at that as well, maybe, this script is preventing me from doing the sliding script.

using UnityEngine;
using System.Collections;

public class JumpScript : MonoBehaviour {

    public float jumpHeight;

    public Transform groundCheck;
    public float groundCheckRadius;
    public LayerMask whatIsGround;
    private bool grounded;

    float jumpTime, jumpDelay = 0.6f;
    bool jumped;


    Animator anim;

    // Use this for initialization
    void Start () {

        anim = GetComponent<Animator>();
           
    }

    void FixedUpdate(){
   
        grounded = Physics2D.OverlapCircle (groundCheck.position, groundCheckRadius, whatIsGround);
   
    }
   
    // Update is called once per frame
    void Update () {
   


        if (Input.GetKeyDown (KeyCode.Space) && grounded) {

            GetComponent<Rigidbody2D> ().velocity = new  Vector2 (0, jumpHeight);
            anim.SetTrigger("Jump");
            jumped = true;
       
        }

        jumpTime -= Time.deltaTime;
        if (jumpTime <= 0 && grounded && jumped) 
        {

            anim.SetTrigger ("Land");
            jumped = false;

        }





    }
}

You have to reset the triggers.

1 Like

Sorry, was too fast when I replied. While you execute and get the wrong behavior, you can have a look at the state machine and its parameters (“Land”, “Jump”, …). Have a look at them whether they are correct at all the times. It seems to me that there is something wrong and not correctly set and reset as needed.

1 Like

Running and Sliding work at the same time, could that give you any hints ?

Hey thanks mate though I figured out. You gave me an idea and I fixed it. All I had to do is to make Slide as a trigger instead of boolean.

You have a certain logic in mind how things are supposed to work. You have the possibility to see where things get wrong when you watch the state machine and the parameters while you are actually in play mode. Like that you can identify what is going wrong.
Here is a quick example of what I mean:

Edit: Good to hear you solved it

1 Like