Unity视⾓控制和Camera的移动类似第⼀⼈称射击游戏
把脚本绑定到camera⾥
using UnityEngine;
using System.Collections;
public class CameraControll : MonoBehaviour {
public float near = 20.0f;
public float far = 100.0f;
public float nsitivityX = 10f;迈克尔 爱默生
public float nsitivityY = 10f;
public float nsitivetyZ = 0f;
public float nsitivetyMove = 10f;
public float nsitivetyMouWheel = 2f;
public int speed = 1;
public Camera camera;
void start(){
ogmcamera = GetComponent<Camera> ();
}
void Update () {
//w键前进
if(Input.GetKey(KeyCode.W))
{
transform.Translate(new Vector3(0,0,speed*Time.deltaTime));
}
//s键后退
if(Input.GetKey(KeyCode.S))
reflections{
江畔独步寻花其六transform.Translate(new Vector3(0,0,-1*speed*Time.deltaTime));
}
//a键后退
if(Input.GetKey(KeyCode.A))
{
transform.Translate(new Vector3(-1*speed,0,0*Time.deltaTime));
}
jake lloyd
/
/d键后退
if(Input.GetKey(KeyCode.D))
{
transform.Translate(new Vector3(speed,0,0*Time.deltaTime));
}
// 滚轮实现镜头缩进和拉远
/*
* if (Input.GetAxis("Mou ScrollWheel") != 0)
{爱你胜过爱自己
camera.fieldOfView =this.camera.fieldOfView - Input.GetAxis("Mou ScrollWheel")*nsitivetyMouWheel;
camera.fieldOfView = Mathf.Clamp(this.camera.fieldOfView, near, far);
}
*/
//⿏标实现视⾓转动,类似第⼀⼈称视⾓
//if (Input.GetMouButton(1))
//{
float rotationX = Input.GetAxis("Mou X") * nsitivityX;
//float rotationY = Input.GetAxis("Mou Y") * nsitivityY; transform.Rotate(-0, rotationX, 0);
// transform.Rotate(-rotationY, 0, 0);
库克大学//}
//键盘按钮←和→实现视⾓⽔平旋转
/*
if (Input.GetAxis("Horizontal")!=0)
{
float rotationZ=Input.GetAxis("Horizontal") * nsitivetyZ; transform.Rotate(0, 0, rotationZ);美国国会大厦暴力事件
}
*/
花絮英文}bth
}
参考: