My Player_Rest animation is Cutting off my Player_Jump animation before it runs all the way.
I really only need it to run once.
(see my current code below)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController2D : MonoBehaviour {
Animator animator;
Rigidbody2D rb2d;
SpriteRenderer spriterenderer;
bool isGrounded;
[SerializeField]
Transform groundcheck;
// Start is called before the first frame update
void Start () {
animator = GetComponent();
rb2d = GetComponent();
spriterenderer = GetComponent();
}
private void FixedUpdate()
{
if(Physics2D.Linecast(transform.position,groundcheck.position, 1 << LayerMask.NameToLayer(“Ground”)))
{
isGrounded = true;
}
else
{
isGrounded = false;
}
if (Input.GetKey(“d”) || Input.GetKey(“right”))
{
rb2d.velocity = new Vector2(4, rb2d.velocity.y);
animator.Play(“Player_Run”);
spriterenderer.flipX = false;
}
else if (Input.GetKey(“a”) || Input.GetKey(“left”))
{
rb2d.velocity = new Vector2(-4, rb2d.velocity.y);
animator.Play(“Player_Run”);
spriterenderer.flipX = true;
}
else
{
animator.Play(“Player_Rest”);
rb2d.velocity = new Vector2(0, rb2d.velocity.y);
}
if(Input.GetKey(“space”) && isGrounded)
{
animator.Play(“Player_Jump”);
rb2d.velocity = new Vector2(rb2d.velocity.x, 5);
}
}
}