- Home /
Question by
Maestro_Kitty · Aug 24, 2016 at 09:06 AM ·
animation2d-platformer
Jump animation will not play
I'm making a 2d platformer, and I've already figured out how to make the player character jump. However, I want to play a jumping animation for whenever the player jumps. Here is my current script, though it should be noted that I've been using the Animator.
public class JumpScript : MonoBehaviour
{
public float jumpHeight;
void Start()
{
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
GetComponent<Rigidbody2D>().AddForce(Vector2.up * jumpHeight);
GetComponent<Animation>("PlayerJump");
}
}
}
Comment
GetComponent<Animation>("PlayerJump");
syntax is not correct.
check Animator , you have to create animation controller and assign it to Animator as explained in manual.
Answer by Rajeesh_AR · Aug 24, 2016 at 09:19 AM
gameObject.GetComponent<Animation>().Play("PlayerJump"); // putting "gameObject." is not necessary
All the properties of Animation can be found on the Unity Doc
Your answer
Follow this Question
Related Questions
2d character stuck in jump 0 Answers
A problem regarding to player animation with checkpoint in 2D platformer 0 Answers
2D animation diferent right and left 0 Answers
Animation Problem 1 Answer
how to add 2d cutscenes to unity 2 Answers