想要在Unity进行键盘漫游和鼠标缩放,可参考如下代码
脚本要绑定在相机上哦!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ViewController : MonoBehaviour {
// Update is called once per frame
//移动速度
public float speed = 1;
//缩放速度
public float mouseSpeed = 60;
void Update () {
//水平移动
float h = Input.GetAxis("Horizontal");
//垂直移动
float v = Input.GetAxis("Vertical");
//缩放移动
float mouse = Input.GetAxis("Mouse ScrollWheel");
transform.Translate(new Vector3(h*speed,mouse*mouseSpeed,v*speed)*Time.deltaTime,Space.World);
}
}
实现的效果如下