using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MotionControl : MonoBehaviour
{
public float speed = 3f; //定义一个速度
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//控制物体移动
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
transform.Translate(new Vector3(horizontal, 0, vertical) * speed * Time.deltaTime);
}
}
Edit - Project Settings - Input Manager
它的名字是 Horizontal ,控制左右的分别是 a 和 d 键
下面还有一个 Vertical,是控制前后的