Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 $$anonymous$$ · Mar 31, 2018 at 04:40 PM · cursorfirst person controller

Stop Unity from hiding mouse cursor?

Hello, I'm making a generic Minecraft clone because I have nothing better to do, but Unity keeps hiding the mouse cursor even when I write code to show it. I'm using Unity's generic First Person Controller as the player.

         if (Input.GetKeyDown ("e")){
             if (CraftingGridShown) {
                 CraftingGridShown = false;
                 CraftingGrid.SetActive (false);
                 Cursor.visible = false;
             }
             else{
                 CraftingGridShown = true;
                 CraftingGrid.SetActive (true);
                 Cursor.visible = true;
             }
         }


EDIT: The issue is that although my code is working, a line of code which is calling some methods is working against it, but I can find a way to access the script so that I can disable it and enable it when needed.

 m_MouseLook.LookRotation (transform, m_Camera.transform);

EDIT: I'm trying to directly access the methods of the MouseLook script, but for some reason it keeps complaining about the object reference not set to an instance of an object.

 void Start () {
     //Cursor.SetCursor (MouseTexture, Vector3.zero, CursorMode.Auto);
     TheCam = Camera.main;
     MouseLookScript.Init(transform , TheCam.transform);
 }

 void Update () {

     if (Input.GetKeyDown ("e")){
         if (CraftingGridShown) {
             CraftingGridShown = false;
             CraftingGrid.SetActive (false);
             Cursor.visible = false;
         }
         else{
             CraftingGridShown = true;
             CraftingGrid.SetActive (true);
             Cursor.visible = true;
         }
     }

     if (CraftingGridShown == false) {
         MouseLookScript.LookRotation (transform, TheCam.transform);
     }


Comment
Add comment · Show 8
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 andrew-lukasik · Mar 31, 2018 at 05:07 PM 0
Share
 Cursor.visible = false;

Change to

 //Cursor.visible = false;
avatar image $$anonymous$$ andrew-lukasik · Mar 31, 2018 at 05:23 PM 0
Share

Wouldn't that just make it a comment and not do anything?

avatar image andrew-lukasik $$anonymous$$ · Mar 31, 2018 at 05:42 PM 0
Share

precisely : )

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by $$anonymous$$ · Apr 01, 2018 at 03:48 AM

The default FirstPersonController script was annoying and I only needed a small section of it (the first person view), so I found something easier to work with here I was able to easily switch everything in the script on and off.

 using UnityEngine;
 using System;
 using System.Collections;
 
 public class CameraMouseLook : DavidBehaviour{
 
     Vector2 MouseLook;
     Vector2 SmoothV;
     public float Sensitivity = 5;
     public float Smoothing = 2;
 
     public bool CanMove;
 
     void Update(){
         if (CanMove) {
             var MD = new Vector2 (Input.GetAxisRaw ("Mouse X"), Input.GetAxisRaw ("Mouse Y"));
 
             MD = Vector2.Scale (MD, new Vector2 (Sensitivity * Smoothing, Sensitivity * Smoothing));
             SmoothV.x = Mathf.Lerp (SmoothV.x, MD.x, Smoothing);
             SmoothV.y = Mathf.Lerp (SmoothV.y, MD.y, Smoothing);
             MouseLook += SmoothV;
 
             Camera.main.transform.localRotation = Quaternion.AngleAxis (-MouseLook.y, Vector3.right);
             transform.localRotation = Quaternion.AngleAxis (MouseLook.x, transform.up);
         }
     }
 }
Comment
Add comment · Share
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
0

Answer by RVDL_IT · Mar 31, 2018 at 08:10 PM

Have you tried to use Screen.showCursor? I believe that it does practically the same thing.

Comment
Add comment · Show 1 · Share
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 $$anonymous$$ · Mar 31, 2018 at 10:15 PM 0
Share

I'm pretty sure that Screen.showCursor is obselete.

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

79 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

Related Questions

Controlling the mouse in an FPSController 0 Answers

Cursor not getting centered 0 Answers

Can anyone translate this to C# (Change cursor appearance) 1 Answer

Lock mouse position with a Rect, possible? 1 Answer

Particle Emitter from moving object to cursor location 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