Search Unity

unity 5 webgl rotate on click issue

Discussion in 'Immediate Mode GUI (IMGUI)' started by cgidesign, Jul 13, 2015.

  1. cgidesign

    cgidesign

    Joined:
    Jul 10, 2015
    Posts:
    3
    hi guys

    I seem to be having an issue with this script, in unity it works fine but once built it doesn't seem to work.

    what its meant to do:
    left click on screen allows you to rotate around a model

    what its doing once built:
    always rotating around model without click

    Code (JavaScript):
    1. var target : Transform;
    2. var distance = 10.0;
    3.  
    4. var xSpeed = 250.0;
    5. var ySpeed = 120.0;
    6.  
    7. var yMinLimit = -20;
    8. var yMaxLimit = 80;
    9.  
    10. private var x = 0.0;
    11. private var y = 0.0;
    12.  
    13. @script AddComponentMenu("Camera-Control/Mouse Orbit")
    14.  
    15. function Start () {
    16.     var angles = transform.eulerAngles;
    17.     x = angles.y;
    18.     y = angles.x;
    19.  
    20.     // Make the rigid body not change rotation
    21.        if (GetComponent.<Rigidbody>())
    22.         GetComponent.<Rigidbody>().freezeRotation = true;
    23. }
    24.  
    25. function LateUpdate () {
    26.     if (target && Input.GetMouseButton(0)) {
    27.         x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
    28.         y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
    29.        
    30.          y = ClampAngle(y, yMinLimit, yMaxLimit);
    31.                
    32.         var rotation = Quaternion.Euler(y, x, 0);
    33.         var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
    34.        
    35.         transform.rotation = rotation;
    36.         transform.position = position;
    37.     }
    38. }
    39.  
    40. static function ClampAngle (angle : float, min : float, max : float) {
    41.     if (angle < -360)
    42.         angle += 360;
    43.     if (angle > 360)
    44.         angle -= 360;
    45.     return Mathf.Clamp (angle, min, max);
    46. }
    has anyone come across this issue before?

    Thanks

    Ahmed