Advertisement
evelynshilosky

HorseMouseMovement

Apr 26th, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class HorseMouseMovement : MonoBehaviour
  4. {
  5.     public float mouseSensitivity = 100f;
  6.  
  7.     private float yRotation = 0f;
  8.  
  9.     private bool isActive = false;
  10.  
  11.     void Start()
  12.     {
  13.         // Locking the cursor to the middle of the screen and making it invisible
  14.         Cursor.lockState = CursorLockMode.Locked;
  15.     }
  16.  
  17.     void Update()
  18.     {
  19.         if (isActive && !InventorySystem.Instance.isOpen && !CraftingSystem.Instance.isOpen && !MenuManager.Instance.isMenuOpen && !DialogueSystem.Instance.dialogueUIActive && !QuestManager.Instance.isQuestMenuOpen && !StorageManager.Instance.storageUIOpen && !CampfireUIManager.Instance.isUIOpen)
  20.         {
  21.             // Get mouse input
  22.             float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
  23.  
  24.             // Control rotation around y axis (Look left and right)
  25.             yRotation += mouseX;
  26.  
  27.             // Apply rotation only around y axis
  28.             transform.localRotation = Quaternion.Euler(0f, yRotation, 0f);
  29.         }
  30.     }
  31.  
  32.     public void Activate()
  33.     {
  34.         isActive = true;
  35.     }
  36.  
  37.     public void Deactivate()
  38.     {
  39.         isActive = false;
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement