Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by SprinkledSpooks · Nov 24, 2016 at 12:23 AM · scripting problemissuecursoruser interface

Mouse Cursor Problem

I'm currently attempting to write a script that, when a certain UI element is activated, it will allow the player to press the 'E' key to switch cameras to a camera named cam2. So far I am successful, except for one aspect:

The cursor does not show up. I believe that this is due to the fact that the camera is switching from the default FPSController because, when I disable the First Person Controller script in edit mode, the cursor will show up. I tried adding the line:

 Cursor.visible = true;

at the end of the IF statement. By using Debug.Log, I have confirmed that the line of code is executing successfully, but the mouse cursor doesn't appear to actually be appearing once again. I've even attempted to deactivate the FPSController entirely, which I have successfully done so, but the mouse cursor remains invisible. Here's my complete code below:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
  
 public class CameraSwitch : MonoBehaviour {
     public Text activateText;
     public GameObject Jim;
     public Camera cam1;
     public Camera cam2;
     public GameObject player;
  
     // Use this for initialization
     void Start ()
     {
         cam1.enabled = true;
         cam2.enabled = false;
     }
    
     // Update is called once per frame
     void Update ()
     {
         if (Input.GetKeyDown("e"))
         {
             Debug.Log("E Pressed!");
             if (activateText.enabled == true)
             {
                 cam1.enabled = !cam1.enabled;
                 cam2.enabled = !cam2.enabled;
                 player.SetActive(true);
  
                 if (cam2.enabled == true)
                 {
                     Cursor.visible = true;
                     Debug.Log("Cursor should be enabled!");
                     player.SetActive(false);
                 }
             }
         }
     }
 }

Any ideas on how to fix this?

Comment
Add comment · Show 2
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
avatar image Hilous · Nov 25, 2016 at 08:49 AM 0
Share

Have you tried, Cursor.SetCursor()? and force it to the middle of the screen ?

avatar image hexagonius · Nov 25, 2016 at 10:54 AM 0
Share

Toggling visible should be fine. When and where is the false set called? I bet it's executed too and after this setting true.

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

96 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 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 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 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 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 avatar image

Related Questions

MissingReferenceException: The variable (name) of (script) doesn't exist anymore. 0 Answers

Cursor does not contain a definition for 'lockState'/'visible' 2 Answers

How to disable mouse lock script when returning to main menu 1 Answer

Set cursor position at the middle of the screen. 1 Answer

Need help with pause menu and cursor lock script conflict 1 Answer


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