- 最后登录
- 2017-5-15
- 注册时间
- 2012-3-1
- 阅读权限
- 90
- 积分
- 32973
- 纳金币
- 32806
- 精华
- 12
|
下面是java代码,原文转自老外博客,可以考虑下,要在什么时候用下鼠标中键的功能了。
var target : Transform;
var MouseWheelSensitivity = 5;
var MouseZoomMin = 1;
var MouseZoomMax = 7;
private var x = 0.0;
private var y = 0.0;
private var distance = 5.0;
function Start (){
var playerAngle = transform.eulerAngles;
x = playerAngle.y;
y = playerAngle.x;
}
function LateUpdate (){
if (Input.GetAxis("Mouse ScrollWheel") != 0) {
//Debug.Log(Input.GetAxis("Mouse ScrollWheel"));
//Debug.Log(distance);
if (distance >= MouseZoomMin && distance <= MouseZoomMax){
distance -= Input.GetAxis("Mouse ScrollWheel") * MouseWheelSensitivity;
if (distance < MouseZoomMin){distance = MouseZoomMin;}
if (distance > MouseZoomMax){distance = MouseZoomMax;}
}
}
rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(y, x, 0), Time.deltaTime * 3);
position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.rotation = rotation;
transform.position = position;
} |
|