• 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 Graestone45 · Oct 16, 2013 at 04:23 PM · c#guifpsmouselock

How to make a mouselock script

I was wondering how I would go about making a mouselock script in C#, for my FPS. It would be awesome if it could be toggled in a way so that you could still use GUIs.

Comment
Add comment · Show 3
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 Graestone45 · Oct 16, 2013 at 04:34 PM 0
Share

I want to lock the cursor in the center of the screen because if I don't the cursor can go out of the screen and if I click to shoot while it is out of the screen, it will not shoot and stop moving the screen along with the cursor. Also, I am using the First Person Controller prefab that i have attached a gun to.

avatar image deltamish · Oct 16, 2013 at 04:35 PM 0
Share

Sorry my bad i confused my self mouselock with cameralock think i am going nuts.Sorry

avatar image Graestone45 · Oct 16, 2013 at 04:39 PM 0
Share

Lol its all good

2 Replies

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

Answer by Rydrako · Oct 16, 2013 at 04:28 PM

 Screen.lockCursor = true;
Comment
Add comment · Show 4 · 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 Graestone45 · Oct 16, 2013 at 04:37 PM 0
Share

I know about Screen.lockCursor, But I don't know how to implement it.

avatar image deltamish · Oct 16, 2013 at 04:40 PM 0
Share

Well thats really easy all you have to do is

 bool Escape = false;
 
 void Update(){
 if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape)){
 Escape = !Escape;
 }
 
 Screen.lockCursor = Escape;
 }
avatar image Graestone45 · Oct 16, 2013 at 04:43 PM 0
Share

Would I then just attach it to the First Person Controller? Sorry it any of this is obvious, I just started using unity SD$$anonymous$$ a few days ago. Edit: Well, I tried putting it on the first person controller, but now it's saying the I have parsing errors. I understand that uploading an image is unnecessary, but I cant figure out how to get the code sample thing working T_T. As i said, I'm a newbie. alt text

bandicam 2013-10-16 11-45-48-684.jpg (63.0 kB)
avatar image Graestone45 · Oct 16, 2013 at 05:15 PM 0
Share

I was being really stupid lol. I figured it out. all i had to do was add another closing bracket T_T

avatar image
0

Answer by YoungDeveloper · Oct 16, 2013 at 04:27 PM

https://www.google.lv/?gws_rd=cr&ei=M75eUserJKeO4wTzmICICA#q=unity+toggle+cursor+lock&spell=1

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

ammo count help 1 Answer

inherit variable from another script 1 Answer

Help With Crouch/Run Script Causing UI Distortion? Script Included :) 0 Answers

Score/point counter system 1 Answer

Animation problem with mirrored object 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