1.构建物体和对应的脚本
2.完成脚本编辑
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ObjectMoving : MonoBehaviour { // 初始化物体移动速度 public float speed = 1; void Start() { } void Update() { //按下键盘上下左右操作键移动 //上 if (Input.GetKey(KeyCode.UpArrow)) { transform.eulerAngles = new Vector3(0, 0, 0); transform.position += transform.forward * speed; } //下 else if (Input.GetKey(KeyCode.DownArrow)) { transform.eulerAngles = new Vector3(0, 180, 0); transform.position += transform.forward * speed; } //左 else if (Input.GetKey(KeyCode.LeftArrow)) { transform.eulerAngles = new Vector3(0, 270, 0); transform.position += transform.forward * speed; } //右 else if (Input.GetKey(KeyCode.RightArrow)) { transform.eulerAngles = new Vector3(0, 90, 0); transform.position += transform.forward * speed; } } }
3.旋转场景物体构建
4.旋转脚本
using System.Collections; using System.Collections.Generic; using UnityEngine; public class RotationRotate : MonoBehaviour { // 初始化旋转坐标 public Vector3 rotate; void Start() { } void Update() { //旋转坐标获取 Vector3 vector = rotate * Time.deltaTime; //执行旋转 this.transform.Rotate(vector, Space.Self); } }
标签:eulerAngles,物体,Vector3,transform,旋转,Unity,using,speed From: https://www.cnblogs.com/clf125800/p/17101712.html