纳金网
标题:
精简好用的u3d摄像机控制脚本
[打印本页]
作者:
狂风大尉
时间:
2014-10-28 03:17
标题:
精简好用的u3d摄像机控制脚本
private Transform player;
public float scrollSpeed = 6.0f;
public float roundSpeed = 4.2f;
public float _vMinLimit = 15f; //y min limit
public float _vMaxLimit = 55f; //y max limit
public float zoomMin = 3f; //zoom min
public float zoomMax = 8f; //zoom max
float hh;
float vv;
float distance;
// Update is called once per frame
void Update () {
if (!player) {
getPlayer();
}
calPos (aroundView (), scrollView ());
}
float scrollView(){
float wheel = Input.GetAxis ("Mouse ScrollWheel");
float dis = Vector3.Distance (transform.position, player.position);
dis -= wheel * scrollSpeed;
distance = Mathf.Clamp (distance,zoomMin,zoomMax);
return distance;
}
Quaternion aroundView(){
float h = Input.GetAxis ("Mouse X");
float v = Input.GetAxis ("Mouse Y");
Quaternion rt = Quaternion.Euler(transform.eulerAngles);
bool rightMouseDown = Input.GetMouseButton (1);
if (rightMouseDown) {
hh += h * roundSpeed; // horizontal
vv -= v;//vertical
vv = Mathf.Clamp(vv,_vMinLimit,_vMaxLimit);
rt = Quaternion.Euler(vv,hh,0f);
}
return rt;
}
//core code
void calPos(Quaternion angle,float distance){
Vector3 pos = angle*new Vector3 (0f,0f,-distance) + player.position;//core code
transform.position = pos;
transform.rotation = angle;//or use the next method
// transform.LookAt (player.position);
}
void getPlayer(){
player = GameObject.FindGameObjectWithTag (TagsEnum.Player.ToString ()).transform;
hh = transform.eulerAngles.y;
vv = transform.eulerAngles.x;
distance = zoomMax;
}
复制代码
作者:
hyui
时间:
2014-10-28 03:56
good to learn !
作者:
我不再年轻
时间:
2014-10-30 17:21
谢谢楼主分享
作者:
huhumark
时间:
2014-10-31 12:43
感谢分享
欢迎光临 纳金网 (http://rs.narkii.com/club/)
Powered by Discuz! X2.5