创建视频网站,工业园区门户网站建设方案,图片手机网站建设,广州网站模块建设在Unity中#xff0c;使用键盘ADWS键控制物体移动#xff0c;通过鼠标左键控制物体旋转#xff0c;鼠标中键控制物体缩放是再常见不过的方法。
方法如下#xff1a;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class MoveCo…在Unity中使用键盘ADWS键控制物体移动通过鼠标左键控制物体旋转鼠标中键控制物体缩放是再常见不过的方法。
方法如下
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class MoveController : MonoBehaviour
{float moveSpeed 10f;float rotateSpeed 1000f;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){//获取横轴参数float Horizontal Input.GetAxis(Horizontal);//获取垂直参数float Vertical Input.GetAxis(Vertical); //键盘ADWS键控制物体移动。//通过乘于Time.deltaTime就可以让物体以每秒moveSpeed单位的速度向前移动transform.Translate(new Vector3(Horizontal * Time.deltaTime * moveSpeed, 0, Vertical * Time.deltaTime * moveSpeed)); //左键鼠标点击状态下移动鼠标旋转if(Input.GetMouseButton(0)){//通过获取鼠标XY轴移动数值控制物体旋转transform.Rotate(new Vector3(Input.GetAxis(Mouse X) * Time.deltaTime * rotateSpeed, Input.GetAxis(Mouse Y) * Time.deltaTime * rotateSpeed));}//通过获取鼠标中键滑动值控制物体缩放transform.localScale Vector3.one * Input.GetAxis(Mouse ScrollWheel);}
}效果如下Unity 通过键盘鼠标控制物体移动、旋转、缩放_哔哩哔哩_bilibili