var camera1:Camera;
var mousescrollwheel_y:float; //摄像机Y轴的点
var mousescrollwheel_z:float; //摄像机z轴的点
var sensitivityW:float=5; //滚轮敏捷
var pnearviewZ:float=-1; //离近的z点距离
var pnearviewY:float=-1; //离近的Y点距离
var meetdistance:float=3; //光线的距离
var nearview_y:float=-1; //最小Y
var farview_y:float=-5; //最大Y
var nearview_z:float=-1; //最小Z
var farview_z:float=-10; //最大Z
function Start ()
{
mousescrollwheel_z=camera1.transform.localPosition.z;
mousescrollwheel_y=camera1.transform.localPosition.y;
}
function Update () {
mousescrollwheel_z += Input.GetAxis("Mouse ScrollWheel")*sensitivityW;
mousescrollwheel_y += Input.GetAxis("Mouse ScrollWheel")*sensitivityW;
if(mousescrollwheel_z>nearview_z){mousescrollwheel_z=nearview_z;}
else if(mousescrollwheel_z<farview_z){mousescrollwheel_z=farview_z;}
if(mousescrollwheel_y>nearview_y){mousescrollwheel_y=nearview_y;}
else if(mousescrollwheel_y<farview_y){mousescrollwheel_y=farview_y;}
camera1.transform.localPosition.z=mousescrollwheel_z;
camera1.transform.localPosition.y=-mousescrollwheel_y;
var fwd = transform.TransformDirection (-(Vector3.forward));
var hit:RaycastHit;
if (Physics.Raycast (transform.position, fwd, hit,meetdistance)) {
if(hit.transform.tag=="wall"){
camera1.transform.localPosition.z=pnearviewZ;
camera1.transform.localPosition.y=-pnearviewY;
}
}
}