0
votes

I am making a jumping and idle animations in UNITY 3d. Here is the code:

using UnityEngine; using System.Collections;

public class JumpingD : MonoBehaviour {

public Animator anim;
public float JumpSpeed_;
private RigidBody _Character; //rigid body of the Character
public Vector3 JumpVector;

/*The thresh Hold level for the character to jump are
    1: Stay Idle
    25: Jump Up 
    */
void Start () 
{
    anim=GetComponent<Animator>();
    anim.SetFloat("JumpSpeed", 1)
}


void Update () 
{
    anim.SetFloat("JumpSpeed", 1)
   if(Input.GetKeyDown(KeyCode.J))
   {
       _Character.AddForce(JumpVector*Time.deltaTime);
       anim.SetFloat("JumpSpeed", 25)
   }
}

}

The problem is the jump animation don't play even after pressed J key. Always the idle animation plays I want the jump animation to play after I pressed J key and after that the character goes idle again.

1
Don't use unity tag for questions related to Unity3d game engine. There's unity3d tag for that.Max Yankov

1 Answers

0
votes

On the first line of your update method, which gets called every frame, you set "JumpSpeed" to 1. It means that the next frame the player will stop pressing the J key, it will immediately drop to 1, so of course jump animation won't play "after" the player pressed J key.