- 最后登录
- 2022-8-9
- 注册时间
- 2012-8-10
- 阅读权限
- 100
- 积分
- 74990
- 纳金币
- 59338
- 精华
- 28
|
以相机为例,写入以下代码:
public var cm:Camera;//Camera Object
public var maxRotationAngle = 20;//Max Rotation Angle each side
private var currentAngle = .0;
function Update ()
{
var cfAngle = 15 * Time.deltaTime;
if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
cfAngle = -cfAngle;
}
else if(Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
}
else
{
return;
}
var newcurrentAngle = currentAngle + cfAngle;
if(newcurrentAngle > maxRotationAngle) newcurrentAngle = maxRotationAngle;
if(newcurrentAngle < -maxRotationAngle) newcurrentAngle = -maxRotationAngle;
cfAngle = newcurrentAngle - currentAngle;
currentAngle = newcurrentAngle;
cm.transform.Rotate(cm.transform.InverseTransformDirection(Vector3.up) * cfAngle);
}
|
|