- Home /
Animation stuck in loop, how to stop?,How to stop Animation?
Hello, im pretty new to Unity so i thought id follow a tutorial about climbing. It works but when you start the animation it keeps looping. Please help.
Heres the video: https://www.youtube.com/watch?v=ffy6tog8cfw
Heres the code:
public class ClimbUp : MonoBehaviour {
private bool canClimb;
private Rigidbody rb;
private RigidbodyFirstPersonController cc;
public Animator anim;
public Camera parkourCam;
public Camera regularCam;
// Use this for initialization
void Start () {
rb = GetComponent <Rigidbody> ();
cc = GetComponent <RigidbodyFirstPersonController> ();
}
// Update is called once per frame
void Update () {
if (canClimb && Input.GetKeyDown (KeyCode.E)) {
regularCam.depth = 0;
parkourCam.depth = 1;
cc.enabled = false;
rb.isKinematic = true;
anim.SetTrigger("Climb");
StartCoroutine (afterClimb ());
}
}
IEnumerator afterClimb () {
yield return new WaitForSeconds (1);
regularCam.depth = 0;
parkourCam.depth = 1;
cc.enabled = true;
rb.isKinematic = false;
transform.position = parkourCam.transform.position;
}
void OnTriggerEnter (Collider other) {
if (other.tag == "Climb") {
canClimb = true;
}
}
void OnTriggerExit (Collider other) {
canClimb = false;
}
} ,So im pretty new to unity and i followed this tutorial: https://www.youtube.com/watch?v=ffy6tog8cfw It works but it continues looping the animation over and over without end! Please help.
The Code:
ing System.Collections; using System.Collections.Generic; using UnityEngine; using UnityStandardAssets.Characters.FirstPerson;
public class ClimbUp : MonoBehaviour {
private bool canClimb;
private Rigidbody rb;
private RigidbodyFirstPersonController cc;
public Animator anim;
public Camera parkourCam;
public Camera regularCam;
// Use this for initialization
void Start () {
rb = GetComponent <Rigidbody> ();
cc = GetComponent <RigidbodyFirstPersonController> ();
}
// Update is called once per frame
void Update () {
if (canClimb && Input.GetKeyDown (KeyCode.E)) {
regularCam.depth = 0;
parkourCam.depth = 1;
cc.enabled = false;
rb.isKinematic = true;
anim.SetTrigger("Climb");
StartCoroutine (afterClimb ());
}
}
IEnumerator afterClimb () {
yield return new WaitForSeconds (1);
regularCam.depth = 0;
parkourCam.depth = 1;
cc.enabled = true;
rb.isKinematic = false;
transform.position = parkourCam.transform.position;
}
void OnTriggerEnter (Collider other) {
if (other.tag == "Climb") {
canClimb = true;
}
}
void OnTriggerExit (Collider other) {
canClimb = false;
}
}
Answer by Horschty · Jun 18, 2018 at 05:51 PM
Select the *.anim file in the explorer and in the inspector uncheck 'Loop Time'.
Im sorry, again im pretty new so would you please elaborate. I searched in my file explorer for a .anim file but do not know where to look.
But thank you for the response otherwise.
At 2:45 in the video when pressing the "create" button a ClimbingUp.anim file is created. That is what you have to select in the unity project explorer and then the inspector will show some properties you can edit.
Your answer
![](https://koobas.hobune.stream/wayback/20220612165005im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
error keeps looping (smartfox connection) even after I stop testing my game 1 Answer
Where is the problem? 0 Answers
illumination bake problem 1 Answer
I can't put animations on loop. 1 Answer
OnTriggerEnter firing late? 1 Answer