3.
public class PlayerController : MonoBehavIoUr { // Start is called before the first frame update //控制人物移动、血量 public float speed = 100f; Rigidbody2D rbody; //刚体组件 void Start() { rbody = GetComponent<Rigidbody2D>(); } // Update is called once per frame void Update() { float moveX = Input.GetAxisRaw("Horizontal"); //控制水平移动方向 A:-1 D:1 0 float moveY = Input.GetAxisRaw("Vertical"); //控制垂直方向 W:1 S:-1 0 //注意规范书写 Vector2 position = rbody.position; //玩家自身的位置 position.x += moveX * Time.deltaTime; position.y += moveY * Time.deltaTime; //将移动返回给玩家 //transform.position = position; rbody.MovePosition(position); //transform.Translate(transform.right * speed * Time.deltaTime); //首次测试 } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。