Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I was watching an old brackeys video about how to do 2d animation and I'm confident I've followed everything in the tutorial properly. Everything was going fine until I started the jump animation. The jump animation will not stop during the on landing function. The video is here https://www.youtube.com/watch?v=hkaysu1Z-N8&feature=emb_logo and my code is this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public CharacterController2D controller;
public float runSpeed = 80f;
float horiztalMove = 0f;
bool jump = false;
public Animator animator;
// Start is called before the first frame update
// Update is called once per frame
void Update()
{

    horiztalMove = Input.GetAxisRaw("Horizontal") * runSpeed;

    animator.SetFloat("Speed", Mathf.Abs(horiztalMove));

    if (Input.GetButtonDown("Jump"))
        jump = true;
        animator.SetBool("Jumping", true);
}
 public void OnLanding ()
{
    animator.SetBool("Jumping", false);   
}

void FixedUpdate()
{        //move our character
    controller.Move(horiztalMove * Time.fixedDeltaTime, false, jump);
    jump = false;
}

} If there is any other code or screenshots you would like me to send i will.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

In this line, you have not added the "{}".

if (Input.GetButtonDown("Jump"))
        jump = true;
        animator.SetBool("Jumping", true);

Write this instead:

if (Input.GetButtonDown("Jump")
   {
       jump = true;
       animator.SetBool("Jumping", true);
   }

And I have seen the Brackeys Video that you have used... And my question is, have you added the PlayerMovement script to the CharacterController's On Land Event and selected OnLanding() function that you've made in the PlayerMovement script?

Try checking that you've added the OnLanding() and also fix the {} in the line that I've pointed out. Hope I turn out be helpful to you. <3


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...