Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire)
- {
- nextTimeToFire = Time.time + 1f / fireRate;
- cam.transform.Rotate(1, 0, 0);
- }
- ================================================================================================
- using UnityEngine;
- using System.Collections;
- using UnityEngine.Networking;
- [AddComponentMenu("Camera-Control/Mouse Look")]
- public class camMouseLook : NetworkBehaviour
- {
- public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
- public RotationAxes axes = RotationAxes.MouseXAndY;
- public float sensitivityX = 15F;
- public float sensitivityY = 15F;
- public float minimumX = -360F;
- public float maximumX = 360F;
- public float minimumY = -60F;
- public float maximumY = 60F;
- public float fireRate = 15f;
- private float nextTimeToFire = 0f;
- float rotationY = 0F;
- Rigidbody rb;
- public Camera cam;
- void Update()
- {
- if (!isLocalPlayer) return;
- {
- if (axes == RotationAxes.MouseXAndY)
- {
- float rotationX = transform.localEulerAngles.y + Input.GetAxisRaw("Mouse X") * sensitivityX;
- rotationY += Input.GetAxisRaw("Mouse Y") * sensitivityY;
- rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
- transform.Rotate(0, Input.GetAxisRaw("Mouse X") * sensitivityX, 0);
- cam.transform.localEulerAngles = new Vector3(-rotationY, 0);
- }
- else if (axes == RotationAxes.MouseX)
- {
- transform.Rotate(0, Input.GetAxisRaw("Mouse X") * sensitivityX, 0);
- }
- else
- {
- rotationY += Input.GetAxisRaw("Mouse Y") * sensitivityY;
- rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
- transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
- }
- if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire)
- {
- nextTimeToFire = Time.time + 1f / fireRate;
- cam.transform.Rotate(1, 0, 0);
- }
- }
- }
- void Start()
- {
- // Make the rigid body not change rotation
- if (rb)
- rb.freezeRotation = true;
- rb = GetComponent<Rigidbody>();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement