Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges