I am trying to create 2 way of navigating in the runtime scene: the first with a gui interface and the second one with the mouse… but the two seems not to work together
Why the first script only works if the second one is switched off?(it actually return the print function but does not move the camera
)
var zoomin: Texture2D;
function OnGUI () {
if (GUI.Button (Rect(0,Screen.height -64,64,64), zoomin)){
Camera.main.transform.Translate(1,1,1);
print ("you clicked the zoomin icon");
}
var target : Transform;
var edgeBorder = 0.1;
var horizontalSpeed = 360.0;
var verticalSpeed = 120.0;
var minVertical = 20.0;
var maxVertical = 85.0;
var minDistance = 1; //Min distance of the camera from the target
var maxDistance = 20;
private var x = 0.0;
private var y = 0.0;
private var distance = 0.0;
function Start(){
x = transform.eulerAngles.y;
y = transform.eulerAngles.x;
distance = (transform.position - target.position).magnitude;
}
function LateUpdate(){
//Zooming with mouse
distance += Input.GetAxis("Mouse ScrollWheel")*distance;
distance = Mathf.Clamp(distance, minDistance, maxDistance);
var dt = Time.deltaTime;
x -= Input.GetAxis("Horizontal") * horizontalSpeed * dt;
y += Input.GetAxis("Vertical") * verticalSpeed * dt;
y = ClampAngle(y, minVertical, maxVertical);
var rotation = Quaternion.Euler(y, x, 0);
var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.rotation = rotation;
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);
}