给我写一段用unity控制角色移动的代码
时间: 2023-03-12 18:54:40 浏览: 143
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class MoveCharacter : MonoBehaviour { public float speed; void Update () {
if (Input.GetKey(KeyCode.UpArrow)) {
transform.position += Vector3.up * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.DownArrow)) {
transform.position += Vector3.down * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.RightArrow)) {
transform.position += Vector3.right * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.LeftArrow)) {
transform.position += Vector3.left * speed * Time.deltaTime;
}
}
}
以下是使用Unity控制角色移动的代码:using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class MoveCharacter : MonoBehaviour { public float speed; void Update () {
if (Input.GetKey(KeyCode.UpArrow)) {
transform.position += Vector3.up * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.DownArrow)) {
transform.position += Vector3.down * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.RightArrow)) {
transform.position += Vector3.right * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.LeftArrow)) {
transform.position += Vector3.left * speed * Time.deltaTime;
}
}
}
使用Unity控制角色移动的代码如下:using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class MoveCharacter : MonoBehaviour { public float speed; void Update () {
if (Input.GetKey(KeyCode.UpArrow)) {
transform.position += Vector3.up * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.DownArrow)) {
transform.position += Vector3.down * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.RightArrow)) {
transform.position += Vector3.right * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.LeftArrow)) {
transform.position += Vector3.left * speed * Time.deltaTime;
}
}
}
阅读全文