- Home /
 
               Question by 
               GG123 · Feb 07, 2014 at 03:23 AM · 
                javascriptguiinventory systemlock-cursor  
              
 
              Cursor not displaying in the Inventory window
I have having issues while trying to run 2 scripts, "Brackeys Inventory System" & "Realistic FPS Prefab". When I open the Inventory in game I cannot see the cursor, I know the issue is with the FPS prefab, when I change the "Screen.showCursor" and "Screen.lockCursor" in the FPS prefab the player mouse controls stop working, does anyone have a fix for this? Thanks
FPS Prefab Code
 using UnityEngine;
 
 using System.Collections;
 using System.Collections.Generic;
 
 public class SmoothMouseLook : MonoBehaviour {
 
     public float sensitivity = 4.0f;
     [HideInInspector]
     public float sensitivityAmt = 4.0f;//actual sensitivity modified by IronSights Script
 
     private float minimumX = -360f;
     private float maximumX = 360f;
 
     private float minimumY = -85f;
     private float maximumY = 85f;
 
     private float rotationX = 0.0f;
     [HideInInspector]
     public float rotationY = 0.0f;
    
     public float smoothSpeed = 0.35f;
     
     private Quaternion originalRotation;
     private Transform myTransform;
     
     void Start(){         
         if (rigidbody){rigidbody.freezeRotation = true;}
         
         myTransform = transform;//manually set transform for efficiency
         
         originalRotation = myTransform.localRotation;
         //sync the initial rotation of the main camera to the y rotation set in editor
         Vector3 tempRotation = new Vector3(0,Camera.main.transform.eulerAngles.y,0);
         originalRotation.eulerAngles = tempRotation;
         
         sensitivityAmt = sensitivity;//initialize sensitivity amount from var set by player
         
         // Hide the cursor
         Screen.showCursor = false;
     }
 
     void Update(){
         // Hide the cursor
         Screen.lockCursor = true;
         
         if(Time.timeSinceLevelLoad > 1 && Time.timeScale > 0){
             // Read the mouse input axis
             rotationX += Input.GetAxisRaw("Mouse X") * sensitivityAmt * Time.timeScale;//lower sensitivity at slower time settings
             rotationY += Input.GetAxisRaw("Mouse Y") * sensitivityAmt * Time.timeScale;
              
             rotationX = ClampAngle (rotationX, minimumX, maximumX);
             rotationY = ClampAngle (rotationY, minimumY, maximumY);
              
             Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
             Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, -Vector3.right);
             //smooth the mouse input
             myTransform.rotation = Quaternion.Slerp(myTransform.rotation , originalRotation * xQuaternion * yQuaternion, smoothSpeed * Time.smoothDeltaTime * 60 / Time.timeScale);
         }
         
     }
    
     //function used to limit angles
     public static float ClampAngle (float angle, float min, float max){
         angle = angle % 360;
         if((angle >= -360F) && (angle <= 360F)){
             if(angle < -360F){
                 angle += 360F;
             }
             if(angle > 360F){
                 angle -= 360F;
             }         
         }
         return Mathf.Clamp (angle, min, max);
     }
     
 }
Inventory System Code
 #pragma strict
 #pragma downcast
 
 /*This script can be attached if you want to do one of the following things:
 1. Pause/Unpause the game.
 2. Enable/Disable the MouseLook component.
 3. Lock/Unlock the mouse cursor.
 */
 
 
 var pauseGame = true; //Do we want to pause/unpause the game?
 
 var disableMouseLookComponent = false; //Do we want to enable/disable the MouseLook component?
 //These two variables are used when disabling/enabling the MouseLook component.
 var ThePlayer : Transform;
 var TheCamera : Transform;
 
 var lockUnlockCursor = false; //Do we want to lock/unlock the mouse cursor?
 
 //Storing the components
 private var lookAround01 : Behaviour;
 private var lookAround02 : Behaviour;
 
 @script AddComponentMenu ("Inventory/Other/Inv Pause Game")
 
 //Checking for the Inventory object and loading in components.
 function Awake () 
 {
     if (transform.name != "Inventory")
     {
         Debug.LogError("A 'InvPauseGame' script is attached to " + transform.name + ". It needs to be attached to an 'Inventory' object.");
     }
 
     if (disableMouseLookComponent == true)
     {
         if (ThePlayer != null && TheCamera != null)
         {
             if (ThePlayer.GetComponent("MouseLook") != null && TheCamera.GetComponent("MouseLook") != null)
             {
                 lookAround01 = ThePlayer.GetComponent("MouseLook");
                 lookAround02 = TheCamera.GetComponent("MouseLook");
             }
             else
             {
                 Debug.LogError("The 'InvPauseGame' script on " + transform.name + " has a variable called 'disableMouseLookComponent' which is set to true though no MouseLook component can be found under (either) the Player or Camera");
                 disableMouseLookComponent = false;
             }
         }
         else
         {
             Debug.LogError("The variables of the 'InvPauseGame' script on '" + transform.name + "' has not been assigned.");
             disableMouseLookComponent = false;
         }
     }
 }
 
 //This function is called from the InventoryDisplay and Character script.
 function PauseGame (pauseIt : boolean)
 {
     //Locking the cursor
     if (lockUnlockCursor == true)
     {
         if (pauseIt == true)
         {
             Screen.lockCursor = false;
         }
         else
         {
             Screen.lockCursor = true;
         }
     }
     
     //Pausing the game
     if (pauseGame == true)
     {
         if (pauseIt == true)
         {
             Time.timeScale = 0.0;
             Time.fixedDeltaTime = 0.02 * Time.timeScale;
         }
         else
         {
             Time.timeScale = 1.0;
             Time.fixedDeltaTime = 0.02 * Time.timeScale;
         }
     }
     
     //Disabling the MouseLook component
     if (disableMouseLookComponent == true)
     {
         if (ThePlayer != null && TheCamera != null)
         {
             if (pauseIt == true)
             {
                 lookAround01.enabled = false;
                 lookAround02.enabled = false;
             }
             else
             {
                 lookAround01.enabled = true;
                 lookAround02.enabled = true;
             }
         }
         else
         {
             Debug.LogError("The variables of the 'InvPauseGame' script on '" + transform.name + "' has not been assigned.");
         }
     }
 }
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
Unity freezes when changing GUI.Color.a 1 Answer
How can i show the texture in the array? 2 Answers
Detect Text in GUI; Print 1 Answer
Limit on GUI Components? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                