[code=javascript]var target : Transform;
var distance = 20.0;
var mySpeed = 250.0;
private var x = 0.0;
private var y = 0.0;
var xMinLimit=30;
var xMaxLimit=120;
var yMinLimit=30;
var yMaxLimit=120;
function Start () {
var angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
}
function LateUpdate () {
if (Input.GetMouseButton(1)){
x += Input.GetAxis("Mouse X") * mySpeed * 0.02;
x = ClampAngle(x, xMinLimit, xMaxLimit);
y -= Input.GetAxis("Mouse Y") * mySpeed * 0.01;
y = ClampAngle(y, yMinLimit, yMaxLimit);
}
var rotation = Quaternion.Euler(y, x, 0);
transform.rotation = rotation;
var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.position = position;
}
static function ClampAngle (angle : float, min : float, max : float) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
[/code]
————————————————————————————————————————————————————
[code=javascript]var target : Transform;
var distance : float;
var mySpeed = 250.0;
private var x = 0.0;
private var y = 0.0;
var xMinLimit=30;
var xMaxLimit=120;
var yMinLimit=30;
var yMaxLimit=120;
function Start () {
var angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
}
function LateUpdate () {
if (Input.GetMouseButton(0)){
x += Input.GetAxis("Mouse X") * mySpeed * 0.02;
x = ClampAngle(x, xMinLimit, xMaxLimit);
y -= Input.GetAxis("Mouse Y") * mySpeed * 0.01;
y = ClampAngle(y, yMinLimit, yMaxLimit);
}
distance += Input.GetAxis("Mouse ScrollWheel")*30;
if(distance >=400)
distance=400;
if (distance<=50)
distance = 50;
var rotation = Quaternion.Euler(y, x, 0);
transform.rotation = rotation;
var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.position = position;
}
static function ClampAngle (angle : float, min : float, max : float) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
[/code]
|