While testing my game, I noticed that my jumping wouldn’t end. I was wondering how I could fix this. Here’s the script i’m using
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController2D : MonoBehaviour {
Animator animator;
Rigidbody2D rb2d;
SpriteRenderer spriteRenderer;
void Start() {
animator = GetComponent<Animator>();
rb2d = GetComponent<Rigidbody2D>();
spriteRenderer = GetComponent<SpriteRenderer>();
}
private void FixedUpdate()
{
if(Input.GetKey("d") || Input.GetKey("right"))
{
rb2d.velocity = new Vector2(2, rb2d.velocity.y);
animator.Play("Player Run");
}
else if(Input.GetKey("a") || Input.GetKey("left"))
{
rb2d.velocity = new Vector2(-2, rb2d.velocity.y);
animator.Play("Player Run");
}
else
{
animator.Play("Player idle");
}
if(Input.GetKey("space"))
{
rb2d.velocity = new Vector2(rb2d.velocity.x, 3);
animator.Play("Player Jump");
}
}
}