Unity 2D角色跳跃动画不显示问题排查求助
Unity 2D角色跳跃动画Sprite不切换问题
在Unity 2D中实现角色跳跃动画(仅切换静止Sprite帧),代码逻辑显示正常,按下跳跃键时角色可跳跃但Sprite无变化。跟随教程操作,也尝试了其他Animator和Animation窗口教程,但均无法切换跳跃Sprite。
代码实现
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { [SerializeField] private float moveForce = 10f; [SerializeField] private float jumpForce = 11f; private float movementX; private float movementY; private Rigidbody2D myBody; private SpriteRenderer sr; private Animator anim; private string WALK_ANIMATION = "Walk"; private bool isGrounded = true; private string GROUND_TAG = "Ground"; private string JUMP_ANIMATION = "Jump"; private void Awake() { myBody = GetComponent<Rigidbody2D>(); anim = GetComponent<Animator>(); sr = GetComponent<SpriteRenderer>(); } // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { PlayerMoveKeyboard(); AnimatePlayer(); PlayerJump(); } void FixedUpdate() { } void PlayerMoveKeyboard() { movementX = Input.GetAxisRaw("Horizontal"); movementY = Input.GetAxisRaw("Vertical"); transform.position += new Vector3(movementX, 0f, 0f) * Time.deltaTime * moveForce; } void AnimatePlayer() { if (movementX > 0) { anim.SetBool(WALK_ANIMATION, true); sr.flipX = false; } else if (movementX < 0) { anim.SetBool(WALK_ANIMATION, true); sr.flipX = true; } else { anim.SetBool(WALK_ANIMATION, false); } } void PlayerJump() { if (Input.GetButtonDown("Jump") && isGrounded) { isGrounded = false; myBody.AddForce(new Vector2(0f, jumpForce), ForceMode2D.Impulse); anim.SetBool(JUMP_ANIMATION, true); Debug.Log("You should be jumping."); } } private void OnCollisionEnter2D(Collision2D collision) { if(collision.gameObject.CompareTag(GROUND_TAG)) { isGrounded = true; anim.SetBool(JUMP_ANIMATION, false); } } }
当前Animator状态

不确定信息是否完整,可随时要求补充。
已尝试的解决方法
- 修改动画过渡(从行走→跳跃改为 idle→跳跃)
- 移除代码中的行走动画逻辑
- 移除行走→idle的过渡,仅保留行走→跳跃
- 勾选/取消勾选Has Exit Time
- 延长跳跃动画时长
- 调整跳跃动画速度(1→0.5、1→2)
- 在AnimatePlayer函数中添加判断,仅当角色Y值高于地面时设置JUMP_ANIMATION为true
- 尝试用Trigger替代Bool触发跳跃动画(不确定代码是否正确)
控制台显示Jump参数已正确设为true,但角色视觉Sprite无变化,求排查遗漏点。
内容的提问来源于stack exchange,提问作者LittleRukia
相关产品推荐
相关产品推荐

