Skip to main content

一个摄像机选择碰壁脚本(初步)

var camera1:Camera;               //摄像机
var detectpoint:Transform; //设定点
var mousescrollwheel:float; //鼠标中间滚轮,不要修改默认值
var sensitivityW:float=5; //鼠标滚轮敏捷性

var pnearview:float=-1; //碰到物体后摄像机离设定点的距离
var meetdistance:float=3; //人物靠近物体的距离

var nearview:float=-1; //鼠标滚轮滚动 控制摄像机离设定点的最近距离
var farview:float=-10; //鼠标滚轮滚动 控制摄像机离设定点的最远距离

function Start ()
{
mousescrollwheel=camera1.transform.localPosition.z;
}

function Update () {

mousescrollwheel += Input.GetAxis("Mouse ScrollWheel")*sensitivityW;
if(mousescrollwheel>nearview){mousescrollwheel=nearview;}
else if(mousescrollwheel<farview){mousescrollwheel=farview;}
camera1.transform.localPosition.z=mousescrollwheel;

//print(camera1.transform.localPosition.z);

var fwd = detectpoint.transform.TransformDirection (-(Vector3.forward));
if (Physics.Raycast (detectpoint.transform.position, fwd, meetdistance)) {
camera1.transform.localPosition.z=pnearview;
}
}