So I made these conditions in animator but when I play the game the idle animation (Ten) plays once then the jumping animation (Ten air) starts and it stays like that.
Your script itself isn’t actually setting any values on your Animator Controller. If they’re not being set elsewhere, (another script or the Animator Window) then the values for Grounded and Speed will be set to default values. Grounded = false and Speed = 0.
This would mean that the behavior you’re describing is what’s to be expected.
Because Ten’s exit condition is that Grounded be set to false (which is set to false by default when creating the parameter), the state will immediately transition to Ten air. Because Ten air has two exit conditions (Grounded = true, speed < 0.1) the animation will never transition out since Grounded is only ever set to false.
You’re going to need to make a reference to the animator controller component so that we can set these values at runtime.
Take a look at this Unity Documentation regarding playing jumping animations as well.
Something like this would be a good place to start:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float speed = 50f;
public Animator animatorController;
private Rigidbody2D rb2d;
// Use this for initialization
void Start ()
{
rb2d = gameObject.GetComponent<Rigidbody2D>();
//If you want the Animator Controller reference to be set on Start, use this line
//This will grab the Animator Controller reference attached to the gameObject this script is assigned to
if(animatorController == null)
{
animatorController = gameObject.GetComponent<AnimatorController>();
}
}
void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
rb2d.AddForce((Vector2.right * speed) * h);
if(h >= 0.1)
{
animatorController.SetBool("Grounded", false);
}
else
{
animatorController.SetBool("Grounded",true);
}
}
}
I doubt this is the desired behavior you have intended, but it’s a good place to start.