Guest User

Untitled

a guest
May 29th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. var target : Transform;
  2. var distance = 10.0;
  3.  
  4. var xSpeed = 250.0;
  5. var ySpeed = 120.0;
  6.  
  7. var sSpeed = 1;
  8. var distMin = 10.0;
  9. var distMax = 100.0;
  10.  
  11. var yMinLimit = -20;
  12. var yMaxLimit = 80;
  13.  
  14. var newMask : LayerMask;
  15. var oldMask : LayerMask;
  16. var radarDistance = 50.0;
  17. var radarView = false;
  18.  
  19. private var x = 0.0;
  20. private var y = 0.0;
  21.  
  22.  
  23.  
  24. @script AddComponentMenu("Camera-Control/Mouse Orbit")
  25.  
  26. function Start () {
  27. var angles = transform.eulerAngles;
  28. x = angles.y;
  29. y = angles.x;
  30.  
  31. // Make the rigid body not change rotation
  32. if (rigidbody)
  33. rigidbody.freezeRotation = true;
  34. }
  35.  
  36.  
  37. function LateUpdate () {
  38. if (target) {
  39. distance +=-(Input.GetAxis("Mouse ScrollWheel")*distance);
  40. if (distance<distMin) distance=distMin;
  41. if (distance>distMax) distance=distMax;
  42.  
  43. if ((radarView == false)&&(distance>radarDistance)) {
  44. camera.cullingMask=newMask;
  45. radarView = true;
  46. }
  47. if ((radarView == true)&&(distance<radarDistance)) {
  48. camera.cullingMask=oldMask;
  49. radarView = false;
  50. }
  51. var rotation = Quaternion.Euler(y, x, 0);
  52. var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
  53.  
  54. transform.rotation = rotation;
  55. transform.position = position;
  56.  
  57. if (Input.GetMouseButton(1)) {
  58. x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
  59. y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
  60.  
  61. y = ClampAngle(y, yMinLimit, yMaxLimit);
  62.  
  63. //transform.rotation = rotation;
  64. //transform.position = position;
  65. }
  66. }
  67. }
  68.  
  69. static function ClampAngle (angle : float, min : float, max : float) {
  70. if (angle < -360)
  71. angle += 360;
  72. if (angle > 360)
  73. angle -= 360;
  74. return Mathf.Clamp (angle, min, max);
  75. }
Advertisement
Add Comment
Please, Sign In to add comment