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
0
Question by liu264 · Nov 28, 2011 at 01:47 AM · menucursor

lcokCursor for ingame menu doesn't work, NEED HELP!!!

I am trying to create a simple in game menu but I just can't get it to work. Everything looks fine, it doesn't work and it keeps doing wired stuff (like if I am standing in front of an interactive charactor in my game, the code works!) Otherwise the cursor will not lock. It seems like the cursor is constantly being locked and unlocked somehow. Please help.

 var menuSkin : GUISkin;

private var openMenu : boolean = false;

function OnGUI()

{

 if(openMenu)

 {

     Time.timeScale = 0;

     

     GUI.skin = menuSkin;

     

     GUI.Box(Rect((Screen.width/2)-100,(Screen.height/2)-110,200,220),"");

     

     if(GUI.Button( Rect( (Screen.width/2)-100, (Screen.height/2)-100, 200, 60),"Resume"))

     {

         Screen.lockCursor = true;

         openMenu = false;

     }

     if(GUI.Button( Rect( (Screen.width/2)-100, (Screen.height/2)-30, 200, 60),"Main Menu"))

     {

         openMenu = false;

         OpenLevel("Deadly Nightshade Start Menu");

     }

     if(GUI.Button( Rect( (Screen.width/2)-100, (Screen.height/2)+40, 200, 60),"Quit"))

     {

         Application.Quit();

     }

 }

 else

     Time.timeScale = 1;

}

function Update()

{

 if(!openMenu && Input.GetButtonDown("Q"))

 {

     openMenu = true;

     Screen.lockCursor = false;

 }

 else if(openMenu && Input.GetButtonDown("Q"))

 {

     openMenu = false;

     Screen.lockCursor = true;

 }

}

function OpenLevel(level:String)

{

 //audio.PlayOneShot(beep);

 Application.LoadLevel(level);

}

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 WillTAtl · Nov 28, 2011 at 02:11 AM 0
Share

no idea what to tell you, I copy-pasted your code to a test script attached to a camera in an empty scene, just changed input button "Q" to "Fire2" which is defined by default and commented out the call to OpenLevel, and it seems to work fine.

Since the script itself seems fine, it must be something else. What are you attaching this script to? Does any other script access this one? What is your build target? If web, what browsers are you testing in?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by liu264 · Nov 28, 2011 at 05:35 AM

I fixed it. Remember when I said if I am standing in front of an interactive character in my game, the code works. That's why, I locked the cursor when checking states in my interactive GUI code.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Hiding the cursor on a certain level. Pause Menu help. 2 Answers

My Mouse Cursor is locked in certain scenes 1 Answer

how to show cursor on specific time? 2 Answers

Unity 3D C# - Scripts ot true false not working 2 Answers

Returning to main menu 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