unity主要通过键盘移动的方法有position,刚体,Translate.......下面就是用Translate方法移动的。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class 你的脚本名字 : MonoBehaviour
{
// Start is called before the first frame update
public float speed; //移动速度
void Start()
{
}
// Update is called once per frame
void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(horizontalInput, verticalInput, 0f) * speed * Time.deltaTime;
transform.Translate(movement);
}
}
写好后,弄好速度,附给你要通过键盘移动的物体。