Advertisement
Guest User

Untitled

a guest
May 26th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire)
  2. {
  3.  
  4. nextTimeToFire = Time.time + 1f / fireRate;
  5. cam.transform.Rotate(1, 0, 0);
  6.  
  7. }
  8.  
  9. ================================================================================================
  10.  
  11. using UnityEngine;
  12. using System.Collections;
  13. using UnityEngine.Networking;
  14.  
  15. [AddComponentMenu("Camera-Control/Mouse Look")]
  16. public class camMouseLook : NetworkBehaviour
  17. {
  18.  
  19. public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
  20. public RotationAxes axes = RotationAxes.MouseXAndY;
  21. public float sensitivityX = 15F;
  22. public float sensitivityY = 15F;
  23.  
  24. public float minimumX = -360F;
  25. public float maximumX = 360F;
  26.  
  27. public float minimumY = -60F;
  28. public float maximumY = 60F;
  29.  
  30. public float fireRate = 15f;
  31.  
  32. private float nextTimeToFire = 0f;
  33.  
  34. float rotationY = 0F;
  35.  
  36. Rigidbody rb;
  37. public Camera cam;
  38.  
  39. void Update()
  40. {
  41. if (!isLocalPlayer) return;
  42. {
  43. if (axes == RotationAxes.MouseXAndY)
  44. {
  45. float rotationX = transform.localEulerAngles.y + Input.GetAxisRaw("Mouse X") * sensitivityX;
  46.  
  47. rotationY += Input.GetAxisRaw("Mouse Y") * sensitivityY;
  48. rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
  49.  
  50. transform.Rotate(0, Input.GetAxisRaw("Mouse X") * sensitivityX, 0);
  51. cam.transform.localEulerAngles = new Vector3(-rotationY, 0);
  52. }
  53. else if (axes == RotationAxes.MouseX)
  54. {
  55. transform.Rotate(0, Input.GetAxisRaw("Mouse X") * sensitivityX, 0);
  56. }
  57. else
  58. {
  59. rotationY += Input.GetAxisRaw("Mouse Y") * sensitivityY;
  60. rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
  61.  
  62. transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
  63. }
  64.  
  65. if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire)
  66. {
  67.  
  68. nextTimeToFire = Time.time + 1f / fireRate;
  69. cam.transform.Rotate(1, 0, 0);
  70.  
  71. }
  72. }
  73. }
  74.  
  75. void Start()
  76. {
  77. // Make the rigid body not change rotation
  78. if (rb)
  79. rb.freezeRotation = true;
  80. rb = GetComponent<Rigidbody>();
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement