uinty 为什么一旋转鼠标镜头就倒了_【Unity3D脚本:RPG的镜头跟随脚本 unity限制旋转角度范围 unity怎样设置rotation mouse x unity unity拖动物体移动 ...

[C#] 纯文本查看 复制代码using UnityEngine;

using System.Collections;

public class MouseFollow_ForRPG_CSharp : MonoBehaviour {

public GameObject target;

public float ZoomSpeed = 30;//镜头缩放速率

public float MovingSpeed = 1;//镜头移动速率

public float RotateSpeed = 1; //镜头旋转速率

public float distance = 20;//设置距离角色的距离

public float ViewAngle = 30;//设置镜头斜视的角度

void Start () {

if(target){

transform.rotation = Quaternion.Euler(ViewAngle, target.transform.rotation.eulerAngles.y,0 );

transform.position = transform.rotation * new Vector3(0,0,-distance)+target.transform.position;

}

}

void Update () {

Quaternion rotation;

Vector3 position;

float delta_x,delta_y;

float delta_rotation_x,delta_rotation_y;

if(target){

if(Input.GetMouseButton(0))

{

delta_x = Input.GetAxis("Mouse X") * MovingSpeed;

delta_y = Input.GetAxis("Mouse Y") * MovingSpeed;

rotation = Quaternion.Euler(0, transform.rotation.eulerAngles.y,0 );

transform.position = rotation * new Vector3(-delta_x,0,-delta_y)+ transform.position;

}

else{

if(Input.GetAxis("Mouse ScrollWheel")!= 0){

distance += -Input.GetAxis("Mouse ScrollWheel") * ZoomSpeed;

}

if (Input.GetMouseButton(1)) {

delta_rotation_x = Input.GetAxis("Mouse X") * RotateSpeed;

delta_rotation_y = -Input.GetAxis("Mouse Y") * RotateSpeed;

transform.Rotate(0,delta_rotation_x,0,Space.World);

transform.Rotate(delta_rotation_y,0,0);

}

else {

transform.rotation = Quaternion.Slerp(transform.rotation,

Quaternion.Euler(transform.rotation.eulerAngles.x, target.transform.rotation.eulerAngles.y,0

),Time.deltaTime*2);

}

transform.position = transform.rotation* new Vector3(0,0,-distance)+ target.transform.position;

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值