unity子弹射击代码 3D 如何访问AXIS摄像头

unity怎样实现鼠标控制摄像头移动
[问题点数:40分,无满意结帖,结帖人lcdxlh]
本版专家分:0
结帖率 100%
CSDN今日推荐
本版专家分:0
匿名用户不能发表回复!|
其他相关推荐unity3d鼠标滚轮实现摄像头拉近后退_百度知道
unity3d鼠标滚轮实现摄像头拉近后退
void Update ()
target = GameObject.Find(&new_offer&);
// 滚轮设置
相机与人物的距离.
if(Input.GetAxis(&Mouse ScrollWheel&) != 0)
theDistance = theDistance + Input.GetAxis(&Mouse ScrollWheel&) *
Time.deltaT...
答题抽奖
首次认真答题后
即可获得3次抽奖机会,100%中奖。
不是distance,是fieldOfView,把下面的代码保存为C#再赋给主相机using UnityEusing System.Cpublic class CubeStatic : MonoBehaviour{
public float minFov = 15f;
public float maxFov = 90f;
public float sensitivity = 10f;
void Update()
float fov = Camera.main.fieldOfV
fov += Input.GetAxis(&Mouse ScrollWheel&) *
fov = Mathf.Clamp(fov, minFov, maxFov);
Camera.main.fieldOfView =
采纳率:45%
为您推荐:
其他类似问题
您可能关注的内容
鼠标滚轮的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。扫一扫体验手机阅读
unity3d实现控制摄像机放大缩小视野加左右可旋转视角角度
<span type="1" blog_id="1610843" userid='
71篇文章,20W+人气,0粉丝
<span type="1" blog_id="1610843" userid='unity摄像机操控功能分享
工作中用到的操控,整理一下进行分享,是修改加copy。。。。自由查看控制功能。
直接上代码:
using UnityE
using System.C
[AddComponentMenu("Camera-Control/Max Camera v2")]
public class MaxCameraV2 : MonoBehaviour
public Vector3 targetO
public float distance = 5.0f;
public float maxDistance = 20;
public float minDistance = .6f;
public float xSpeed = 200.0f;
public float ySpeed = 200.0f;
public int yMinLimit = -80;
public int yMaxLimit = 80;
public int zoomRate = 40;
public int ozoomRate = 40;
public float panSpeed = 0.3f;
public float zoomDampening = 5.0f;
public float ozoomDampening = 500.0f;
private float xDeg = 0.0f;
private float yDeg = 0.0f;
private float currentD
private float desiredD
private Quaternion currentR
private Quaternion desiredR
private Vector3
void Start() { Init(); }
void OnEnable() { Init(); }
public void Init()
//If there is no target, create a temporary target at 'distance' from the cameras current viewpoint
if (!target)
GameObject go = new GameObject("Cam Target");
go.transform.position = transform.position + (transform.forward * distance);
target = go.
distance = Vector3.Distance(transform.position, target.position);
currentDistance =
desiredDistance =
//be sure to grab the current rotations as starting points.
position = transform.
rotation = transform.
currentRotation = transform.
desiredRotation = transform.
xDeg = Vector3.Angle(Vector3.right, transform.right);
yDeg = Vector3.Angle(Vector3.up, transform.up);
public float maxView = 3000.0f;
public float minView = 5.0f;
public float movSpeed = 0.1f;
void LateUpdate()
if (calcSenCtrl.focusWindiow != -1)
// If Control and Alt and Middle button? ZOOM!
if (Input.GetMouseButton(2) && Input.GetKey(KeyCode.LeftAlt) && Input.GetKey(KeyCode.LeftControl))
desiredDistance -= Input.GetAxis("Mouse Y") * Time.deltaTime * zoomRate * 0.125f * Mathf.Abs(desiredDistance);
// If middle mouse and left alt are selected? ORBIT
else if (Input.GetMouseButton(1))
xDeg += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
yDeg -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
////////OrbitAngle
//Clamp the vertical axis for the orbit
yDeg = ClampAngle(yDeg, yMinLimit, yMaxLimit);
// set camera rotation
desiredRotation = Quaternion.Euler(yDeg, xDeg, 0);
currentRotation = transform.
rotation = Quaternion.Lerp(currentRotation, desiredRotation, Time.deltaTime * zoomDampening);
transform.rotation =
// otherwise if middle mouse is selected, we pan by way of transforming the target in screenspace
else if (Input.GetMouseButton(2))
//grab the rotation of the camera so we can move in a psuedo local XY space
target.rotation = transform.
if (Input.GetKey(KeyCode.LeftShift))
target.Translate(Vector3.right * -Input.GetAxis("Mouse X") * panSpeed * 10.0f);
target.Translate(transform.up * -Input.GetAxis("Mouse Y") * panSpeed * 10.0f, Space.World);
target.Translate(Vector3.right * -Input.GetAxis("Mouse X") * panSpeed);
target.Translate(transform.up * -Input.GetAxis("Mouse Y") * panSpeed, Space.World);
else if (Input.GetKey(KeyCode.W))
//grab the rotation of the camera so we can move in a psuedo local XY space
target.rotation = transform.
target.Translate(Vector3.forward * movSpeed);
//target.Translate(transform.up * -Input.GetAxis("Mouse Y") * panSpeed, Space.World);
else if (Input.GetKey(KeyCode.S))
//grab the rotation of the camera so we can move in a psuedo local XY space
target.rotation = transform.
target.Translate(-1.0f * Vector3.forward * movSpeed);
//target.Translate(transform.up * -Input.GetAxis("Mouse Y") * panSpeed, Space.World);
else if (Input.GetKey(KeyCode.A))
//grab the rotation of the camera so we can move in a psuedo local XY space
target.rotation = transform.
target.Translate(-1.0f * Vector3.right * movSpeed);
//target.Translate(transform.up * -Input.GetAxis("Mouse Y") * panSpeed, Space.World);
else if (Input.GetKey(KeyCode.D))
//grab the rotation of the camera so we can move in a psuedo local XY space
target.rotation = transform.
target.Translate(1.0f * Vector3.right * movSpeed);
//target.Translate(transform.up * -Input.GetAxis("Mouse Y") * panSpeed, Space.World);
////////Orbit Position
if (!camera.isOrthoGraphic)
// affect the desired Zoom distance if we roll the scrollwheel
desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * zoomRate * Mathf.Abs(desiredDistance);
//clamp the zoom min/max
desiredDistance = Mathf.Clamp(desiredDistance, minView, maxView);
// For smoothing of the zoom, lerp distance
currentDistance = Mathf.Lerp(currentDistance, desiredDistance, Time.deltaTime * zoomDampening);
if (Input.GetKey(KeyCode.LeftControl))
// affect the desired Zoom distance if we roll the scrollwheel
desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * zoomRate * Mathf.Abs(desiredDistance);
//clamp the zoom min/max
desiredDistance = Mathf.Clamp(desiredDistance, minDistance, maxDistance);
// For smoothing of the zoom, lerp distance
currentDistance = Mathf.Lerp(currentDistance, desiredDistance, Time.deltaTime * zoomDampening);
float size = camera.orthographicS
if (Input.GetKey(KeyCode.LeftShift))
size -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * ozoomRate * 10.0f;
size -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * ozoomR
size = Mathf.Clamp(size, minView, maxView);
camera.orthographicSize = Mathf.Lerp(camera.orthographicSize, size, Time.deltaTime * ozoomDampening);
// calculate position based on the new currentDistance
position = target.position - (rotation * Vector3.forward * currentDistance + targetOffset);
transform.position =
private static float ClampAngle(float angle, float min, float max)
if (angle & -360)
angle += 360;
if (angle & 360)
angle -= 360;
return Mathf.Clamp(angle, min, max);
//public float orgZdampening
public void activeWheel()
//zoomDampening = orgZ
zoomDampening = 5.0f;
public void deActiveWheel()
//orgZdampening = zoomD
zoomDampening = 0.0f;
没有更多推荐了,新人就教: 第三人称摄像机 限制旋转角度问题【unity3d吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:88,015贴子:
新人就教: 第三人称摄像机 限制旋转角度问题收藏
已实现功能:按住鼠标右键时:1.左右滑动鼠标物体可左右旋转。2.上下滑动可让摄像机以物体为中心上下旋转。按下鼠标左键时:滑动鼠标可使摄像机以物体为中心上下左右旋转。希望实现的功能:1.按下左键使摄像机以物体为中心移动,松开左键后摄像机位置自动恢复到移动前的位置(摄像机在X轴上旋转可以,但在Y轴上旋转必须在按下左键的时候,如果旋转后松开左键则回到摄像机移动前的位置)2.如何限制摄像机的旋转角度?
siki老师的Unity3D专业视频学习平台,上千门实时更新课程,供学员在线观看学习!
我在工程中建立的物体:Cube
//我控制的主物体,摄像机以他为中心旋转。Cube本身我也加上了"WSAD"控制前后左右移动的脚本,这个问题不大。xuanzhuan1
//为空物体,是Cube的子物体。xuanzhuan2
//为空物体,是xuanzhuan1的子物体。Main Camera
//摄像机,为xuanzhuan2的子物体。名为”xuanzhuan“的代码依附到这个上面。代码如下:#pragma strictvar y:T
// y 中放 空物体”xuanzhuan2“var x:T
// x 中放 空物体”xuanzhuan1“var y1:T
// y1 中放 空物体”xuanzhuan2“var zhongxin:T
// zhongxin 中放 空物体”xuanzhuan2“function Start () {}function Update () { //鼠标控制旋转if(Input.GetKey(KeyCode.Mouse0)){x.transform.Rotate(0,Input.GetAxisRaw("Mouse X")*360*Time.deltaTime,0,Space.Self);y.transform.Rotate(-1*Input.GetAxisRaw("Mouse Y")*360*Time.deltaTime,0,0,Space.Self);}
if(Input.GetKey(KeyCode.Mouse1)){y1.transform.Rotate(-1*Input.GetAxisRaw("Mouse Y") * 400 * Time.deltaTime,0,0,Space.Self);}//限制旋转角度if(this.transform.eulerAngles.x&81){this.transform.eulerAngles.x=80;}if(this.transform.eulerAngles.x&9){this.transform.eulerAngles.x=10;}}
麻烦各位大大解答一下。。谢谢了先。。
不要沉啊。希望大家帮一下忙。。
想要的是不是Unity 界面里的鼠标 旋转 缩放 平移 功能?
登录百度帐号

我要回帖

更多关于 unity3d引擎 的文章

 

随机推荐