- Home /
Parameter 'Jump' does not exist
I'm currently trying to make a 2D platformer, and everyone was going well until I added animations. When adding the animations and coding them using C#, my jump had stopped working, giving me an error that said, "Parameter 'Jump' does not exist UnityEngine.Animator:SetBool (string,bool)". I then set up a debug that would say, "I should be able to jump" if my code allowed me to jump.
If anyone can help, that would be greatly appreciated. Thanks
My code is bellow:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class NewBehaviourScript : MonoBehaviour { // Start is called before the first frame update //private Rigidbody2D rb; public float moveSpeed = 40f; float jumpForce = 0f;
bool isGrounded = false;
public Transform isGroundedChecker;
public float checkGroundRadius;
public LayerMask groundLayer;
public float fallMultiplier = 2.5f;
public float lowJumpMultiplier = 2f;
public float rememberGroundedFor;
float lastTimeGrounded;
public int defaultAdditionalJumps = 1;
int additionalJumps;
Rigidbody2D rb;
public float speed;
public Animator animator;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
Move();
Jump();
BetterJump();
CheckIfGrounded();
if ((Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D)))
{
animator.SetBool("moving", true);
}
else
{
animator.SetBool("moving", false);
}
if (isGrounded == true)
{
Debug.Log("i should be able to jump");
}
}
void BetterJump()
{
if (rb.velocity.y < 0)
{
rb.velocity += Vector2.up * Physics2D.gravity * (fallMultiplier - 1) * Time.deltaTime;
}
else if (rb.velocity.y > 0 && !Input.GetKey(KeyCode.Space))
{
rb.velocity += Vector2.up * Physics2D.gravity * (lowJumpMultiplier - 1) * Time.deltaTime;
}
}
void CheckIfGrounded()
{
Collider2D colliders = Physics2D.OverlapCircle(isGroundedChecker.position, checkGroundRadius, groundLayer);
if (colliders != null)
{
isGrounded = true;
additionalJumps = defaultAdditionalJumps;
}
else
{
if (isGrounded)
{
lastTimeGrounded = Time.time;
}
isGrounded = false;
}
}
public void Jump()
{
if (Input.GetKeyDown(KeyCode.Space) && (isGrounded || Time.time - lastTimeGrounded <= rememberGroundedFor || additionalJumps > 1))
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
additionalJumps--;
animator.SetBool("Jump", true);
animator.SetTrigger("Jump");
}
void OnLanding()
{
animator.SetBool("Jump", false);
}
if (isGrounded == true)
{
OnLanding();
}
}
void Move()
{
float x = Input.GetAxisRaw("Horizontal");
float moveBy = x * speed;
rb.velocity = new Vector2(moveBy, rb.velocity.y);
}
void oupdate()
{
rb.velocity = Vector2.zero;
if (Input.GetKey(KeyCode.DownArrow))
{
rb.velocity = new Vector2(0, -moveSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.RightArrow))
{
rb.velocity = new Vector2(moveSpeed * Time.deltaTime, 0);
}
if (Input.GetKey(KeyCode.UpArrow))
{
rb.velocity = new Vector2(0, moveSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
rb.velocity = new Vector2(-moveSpeed * Time.deltaTime, 0);
}
}
}
Answer by Caeser_21 · Apr 05 at 09:40 AM
Make sure you have created a bool called 'Jumping' in the animator tab or check the spelling of your bool...