【问题标题】:Animation Starts but player won't move on key press in Unity动画开始,但播放器不会在 Unity 中按下按键移动
【发布时间】:2020-01-07 08:53:09
【问题描述】:

我和 3 位朋友开始制作游戏,在编码时遇到错误,播放器上的动画开始但不会移动。我们正在使用 Unity(C#) 我已经在 Animator 和代码中检查了名称,所以不是这样。

这是代码

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



public class Movement : MonoBehaviour
{
       public float moveSpeed = 5f;
    public Animator anim;
    // Start is called before the first frame update
    void Start()
    {
        anim = GetComponent<Animator>();
    }
        void Update()
    {
        Jump();
        Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f , 0f);
        transform.position += movement * Time.deltaTime * moveSpeed;
        if(Input.GetAxis("Horizontal") > 0){
            anim.SetBool("isWalking", true);
        }
        else
        {
            anim.SetBool("isWalking", false);
        }
    }




    void Jump(){
        if (Input.GetButtonDown("Jump")){
            gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f,5f), ForceMode2D.Impulse);
        }
    }
}

如果重要的话,那就是 2D 游戏

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    你可以尝试在start()中创建rigidbody2d,然后尝试

    rigidbody.AddForce(Vector2(moveSpeed,0), ForceMode2D.Impulse);
    

    【讨论】:

      猜你喜欢
      • 2023-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-19
      • 2021-03-08
      • 2016-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多