Hi,
I’m trying to implement a Crouch control for a platformer. My bool variables appear to be working correctly, but the animation only plays the first frame. I’m obviously not using Exit Time on the Animator as I want the animation to play immediately as it’s a 2D game. I’ve tried various methods in my script, but the frames just don’t play through.
The other scripts I have don’t effect the Crouch script, as the problem persists even when they are disabled (I’m keeping my scripts seperate for future reference and modularity).
I want the player to stay crouched whilst the button is pressed, then when released the crouching is cancelled and it goes back to the Idle animation.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerCrouch : MonoBehaviour
{
public Animator animator;
// Update is called once per frame
void Update()
{
// Crouch True
if (Input.GetButtonDown("Crouch"))
{
Debug.Log("True");
animator.SetBool("isCrouching", true);
}
// Crouch False
if (Input.GetButtonUp("Crouch"))
{
Debug.Log("False");
animator.SetBool("isCrouching", false);
}
}
}