【发布时间】: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 游戏
【问题讨论】: