Unity3D鼠标滚轮控制摄像机远近

js代码:
  //  鼠标中间键
var MouseWheelSensitivity = 5;
var MouseZoomMin = 2;
var MouseZoomMax = 10;
var normalDistance:float;
摄像机距离视角中心最近为2,最远为10,鼠标灵敏度为5
Js代码:
// 如果按住滑轮
if (Input.GetAxis("Mouse ScrollWheel") != 0)
{
//Debug.Log(Input.GetAxis("Mouse ScrollWheel"));
//Debug.Log(distance);
if (normalDistance >= MouseZoomMin && normalDistance <= MouseZoomMax)
{
normalDistance -= Input.GetAxis("Mouse ScrollWheel") * MouseWheelSensitivity;
}
if (normalDistance < MouseZoomMin)
{
normalDistance = MouseZoomMin;
}
if (normalDistance > MouseZoomMax)
{
normalDistance = MouseZoomMax;
}
}
 
 
 
第二种方法:修改第一人称的摄像机FSPTInputController
private var motor : CharacterMotor;
var speedZ=800;
// Use this for initialization
function Awake () {
 motor = GetComponent(CharacterMotor);
}
// Update is called once per frame
function Update () {
 // Get the input vector from kayboard or analog stick
 var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Mouse ScrollWheel")*speedZ);
 
 if (directionVector != Vector3.zero) {
  // Get the length of the directon vector and then normalize it
  // Dividing by the length is cheaper than normalizing when we already have the length anyway
  var directionLength = directionVector.magnitude;
  directionVector = directionVector / directionLength;
  
  // Make sure the length is no bigger than 1
  directionLength = Mathf.Min(1, directionLength);
  
  // Make the input vector more sensitive towards the extremes and less sensitive in the middle
  // This makes it easier to control slow speeds when using analog sticks
  directionLength = directionLength * directionLength;
  
  // Multiply the normalized direction vector by the modified length
  directionVector = directionVector * directionLength;
 }
 
 // Apply the direction to the CharacterMotor
 motor.inputMoveDirection = transform.rotation * directionVector;
 motor.inputJump = Input.GetButton("Jump");
}
// Require a character controller to be attached to the same game object
@script RequireComponent (CharacterMotor)
@script AddComponentMenu ("Character/FPS Input Controller")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值