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
1
Question by sandralc · Apr 05, 2016 at 05:26 AM · unity 5guimousefps controller

How to disable FPS control but allow mouse to move and interact with GUI

I've been looking around for the answer to this question, but couldn't find one that solved my problem, so forgive me if it has already been answered and I couldn't find it. [First post btw, so don't be harsh on me :P]

I have a scene with Unity's prefab FPS controller. After I detect that the player has clicked on an object (a character), I want to freeze the camera and show a GUI with some dialogue text and options, with which the player should be able to interact.

 // Update is called once per frame
 void Update () {
     if (Input.GetButtonDown("Fire1")) {
         RaycastHit hit = new RaycastHit();
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out hit)) {
             if (hit.transform.tag == "NPC")
                 ShowCharacterDialogue(hit.transform.name);
         }
     }
 }

 public void ShowCharacterDialogue (string npcName) {
     characterController.enabled = false;
     characterController.GetComponent<FirstPersonController>().enabled = false;

     characterText.text = "Why are you looking at me?";
     foreach(UnityEngine.UI.Button button in buttons) {
         button.gameObject.SetActive(true);
     }
 }

I am able to disable FPS movement and camera rotation and display the GUI successfully after that, but I can't seem to enable mouse interaction. It stays frozen in the center and I can't click on the GUI buttons. Can anyone help me to find out what is it that I'm doing wrong?

Thank you very much in advance!

Comment
Add comment · Show 1
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 ZefanS · Apr 06, 2016 at 02:13 AM 1
Share

Sounds like you might need to modify the cursor Lock State

1 Reply

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

Answer by sandralc · Apr 06, 2016 at 08:30 PM

@ZefanS thank you for your answer! I had actually tried using Lockstate without success, but I found this thread: http://answers.unity3d.com/questions/1020927/cursorlockstate-not-working.html where it is suggested to set the Lockstate to None before changing the state again, and it worked!

 Cursor.lockState = CursorLockMode.None;
 Cursor.lockState = CursorLockMode.Confined;
 Cursor.visible = true;
Comment
Add comment · Show 2 · 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 ZefanS · Apr 06, 2016 at 11:26 PM 0
Share

Hmm, weird, but I'm glad it worked.

avatar image Kzapas · Jan 25, 2020 at 09:42 PM 0
Share

Holy****! You actually solved my problem! It took me forever to figure it out! Thank you!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Unlocking & "Equipping" Colors onto Sprites with c# 2 Answers

Change GUI on mouse over 1 Answer

detect mouseover with grid buttons? 1 Answer

How do i create an object with a GUI Button 1 Answer

Double Click problems with NGUI? 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