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
1
Question by quantumarchi · Jun 04, 2012 at 09:41 PM · updatescreendlllock-cursor

Lock cursor on the center of screen

i have tried many options with Screen.lockCursor = true; etc

so i was told its possible to use a dll file to lock the cursor in the middle of the screen system.windows.forms.dll is the one im told to use but i dont know how i would start to get it to work or what code i would use in c# to make the cursor center ,

the problem is that i put Screen.lockCursor = true; in code but when i do it OnMouseOver doesnt work or similar things like OnMouseEnter. it works perfectly fine without the lockcursor but with it the on mouse stuff doesnt work

i have tried running the game to see if its just a problem with the in house play .

things i have tried : Screen.lockCursor = true; Screen.lockCursor = false; (in the update)

if(Screen.lockCursor == false) Screen.lockCursor = true; (update also)

either need to fix the problem with lock cursor or use the dll method but i need to be told how to set it up, thanks for any help in advance!

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 artsdcs · Jun 04, 2012 at 09:55 PM 0
Share

whoops sorry i posted the wrong one.

avatar image quantumarchi · Jun 04, 2012 at 09:56 PM 0
Share

what do you mean?

avatar image Berenger · Jun 04, 2012 at 09:57 PM 1
Share

artsdcs : i use this

 function Start (){
     Screen.lockCursor = true; 
 }
avatar image quantumarchi · Jun 04, 2012 at 10:01 PM 0
Share

that makes no difference, even if it did what if the player uses escape the lockcusor changes to false automatically then.

avatar image Eric5h5 · Jun 04, 2012 at 10:32 PM 1
Share

In that case, set lockCursor to false when you don't want it locked, and true every frame otherwise. You can also use raycasting ins$$anonymous$$d of On$$anonymous$$ouseOver.

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by thenachotech1113 · Jun 04, 2012 at 10:28 PM

what I use so u can unlock it in mid game so u can be able to exit out (sorry its in java, u can allways make a new script)

 // lock at beggining
 function Start ()
 {
 Screen.lockCursor = true;
 }
 //unlock in mid game
 
 function Update()
 {
 Screen.showCursor = false;
    
     if (Input.GetKeyDown(KeyCode.P))
         if (Screen.lockCursor)
         Screen.lockCursor = false;
         
     else{
     Screen.lockCursor = true;
 }

}

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 quantumarchi · Jun 04, 2012 at 10:39 PM 0
Share

no exiting out isnt the problem! you can just press escape for that!

im sorry but people dont seem to be understanding,

Screen.lockCursor works! but it stops On$$anonymous$$ouseOver from working on objects! In my game you need to put your mouse over barricades and shops etc for you to use them , GUI comes up, and you can do what you want from there,

But if Screen.lockCursor = true; then the On$$anonymous$$ouseOver does not work. meaning the player cant upgrade and buy things, If Screen.lockCursor = false and the player puts their mouse over and object it works fine, so something about Screen.lockCursor is making it stop working

i must also add i need the cursor to be put in the middle of the screen because thats how i want the gameplay to be like, so if Screen.lockCursor does not work what else can i do?

i have been told a .dll file will allow me to do this But if there is a way to make Screen.lockCursor to work then please tell me .

thank you

avatar image
0

Answer by thunts7 · Aug 10, 2013 at 03:37 AM

im not exactly sure about how the coding would go but you could try to add a gui texture to the middle of the screen and try and raycast from that if possible. basically replace the curser with that.

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 RealSoftGames · Dec 28, 2014 at 12:50 AM

with what you said there about needing the cursor for barricades and shops, cant you just make a BoxCollider and set it to trigger, and make it a realistic distance?

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.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers

Is it possible to lock a cursor without hiding it?? 0 Answers

Lock Cursor in the Center of the Screen? 1 Answer

How can i move an object while the coursor is locked? 1 Answer

How can we use httpwebrequest in editor 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