public class ArrowControl : MonoBehaviour
{
public float moveSpeed = 5f;
// 实例化两个 Cube 并赋予初始位置
//cube1 = Instantiate(cubePrefab, new Vector3(-2f, 0.5f, 0f), Quaternion.identity);
//cube2 = Instantiate(cubePrefab, new Vector3(2f, 0.5f, 0f), Quaternion.identity);
// 添加箭头脚本以控制移动
//cube1.AddComponent<ArrowControl>();
void Update()
{
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(horizontal, 0f, vertical) * moveSpeed * Time.deltaTime;
transform.Translate(movement);
}
}
标签:Vector3,float,0.5,键盘,Unity,添加,0f,new,控制代码 From: https://www.cnblogs.com/guangzhiruijie/p/17491384.html