Can Not Load Animation of Jump
I have problem about my player who I make. It can walk and idle, but it can't jump. This is my source code. Could you help me, please?
using UnityEngine;
using System.Collections;
public class PlayerCowok : MonoBehaviour {
public float maxSpeed = 5;
public float speed = 50f;
public float jumPower = 1000f;
public bool grounded;
private Rigidbody2D rb2d;
private Animator anim;
// Use this for initialization
void Start ()
{
rb2d = gameObject.GetComponent<Rigidbody2D>();
anim = gameObject.GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
anim.SetBool("Grounded", grounded);
//anim.SetFloat("Speed", Mathf.Abs(Input.GetAxis("Horizontal")));
anim.SetFloat("Speed", Mathf.Abs(rb2d.velocity.x));
if (Input.GetAxis("Horizontal") < -0.1f)
{
transform.localScale = new Vector3(-38, 38, 38);
}
if (Input.GetAxis("Horizontal") > 0.1f)
{
transform.localScale = new Vector3(38, 38, 38);
}
if (Input.GetButtonDown ("Jump") && grounded)
{
rb2d.AddForce(Vector2.up * jumPower);
}
}
void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
//moving player
rb2d.AddForce((Vector2.right * speed) * h);
//limiting the speed of player
if (rb2d.velocity.x > maxSpeed)
{
rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y);
}
if (rb2d.velocity.x < -maxSpeed)
{
rb2d.velocity = new Vector2(-maxSpeed, rb2d.velocity.y);
}
}
}
Comment
if (Input.GetButtonDown ("Jump") && grounded)
// you didn't deter$$anonymous$$e how the player will be grounded before testing it & anim.SetBool("Grounded", grounded);
is setting the animator Grounded to grounded which again you didn't deter$$anonymous$$e so you can use grounded = Physics2D.OverlapCircle ();
& sorry it can not be described here so wach this tutorial from $$anonymous$$ute 51 youtube
Your answer
![](https://koobas.hobune.stream/wayback/20220612071924im_/https://answers.unity.com/themes/thub/images/avi.jpg)