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 Jacooboo · Oct 13, 2017 at 02:08 PM · gamemenubackgroundgameplay

How do i make my game to focus on the IN game menu instead of the gameplay

How do i make my game to focus on the IN game menu instead of the gameplay. When i press escape and my IN game menu opens i want the "game" to focus on the menu and not on my fps player in the background. I mean when i have opened the IN game menu and press change weapon class etc my player fires a shot in the background at the same time.. How do i fix this?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by FlyingHighUp · Oct 14, 2017 at 04:58 AM

Unfortunately there isn't a pretty solution right now; you have to create a flag.

In your character controller, check if the main menu is open. If it is, don't take input from Input.GetKeyDown() etc. If you're using a asset store FPS script, they might have a flag coded in there you can set.

Currently the most elegant way to solve this is to code a facade that replaces the Input class (e.g. Unity's CrossPlatformInput class). Then you can set a universal flag to enable/disable player input. But sometimes that's overkill depending on your situation. Maybe once Unity creates the new input system we can finally put this issue to rest.

Comment
Add comment · Show 6 · 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 Jacooboo · Oct 14, 2017 at 03:13 PM 0
Share

Thanks for your help! Can you write here kind of what the code would look like in my character controller to check if the menu is open.

avatar image Glurth Jacooboo · Oct 14, 2017 at 06:14 PM 0
Share

declare:

 private bool menuOpen=false;

when menu is opened, add:

 menuOpen=true;

when menu is close, add:

 menuOpen=false;


check if menu is open, add:

  if(menuOpen) return; //return will skip the rest of the function




avatar image Jacooboo · Oct 14, 2017 at 07:04 PM 0
Share

Glurth is that all i have to write? And what exactly does this mean?

avatar image Glurth Jacooboo · Oct 14, 2017 at 07:36 PM 0
Share
 private bool menuOpen=false;

This line defines a variable in your class. Is states that it is of type "bool" which is short for boolean: meaning it can only two possible values: true or false (stored as a bit, this is one or zero respectively). Sometimes this is also called a flag: which can be (up or down).

 if(menuOpen) return;

This line will evaluate the value of the menuOpen variable. If true, it will invoke the code inside th if statement. I used a shorthand here to not use the { }, which is legal because there is only one command inside the if statement. It is equivalent to:

 if(menuOpen) 
 {
     return;
 }

The return command means that the currently running function is done, and should return program control (what command is invoked next) to wherever the function was invoked from.

This is really basic c# stuff, but still, I suspect these answers will just raise $$anonymous$$ORE questions, and so would recommend an online course on c#.

While that is all you have to write, for flyinguphigh's solution, you do need to make sure you put it in the right places.

avatar image Jacooboo · Oct 14, 2017 at 07:52 PM 0
Share

I guess i can write this in the update function in character controller? Will this code make the gameplay to "stop" while the menu is open?

avatar image Glurth Jacooboo · Oct 14, 2017 at 08:32 PM 0
Share

if you put the if(menuOpen) return; in your character controller's update function, that's all that will be disabled, physics and other updates would not stop running. (how to do that would be a separate question, but I suspect you can find one on that subject, on this site).

avatar image
0

Answer by Jacooboo · Oct 14, 2017 at 08:45 PM

OKey thank you!

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

100 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 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

Game is in paused mode when returning to main menu 0 Answers

Overlaping GUITexture, help! 1 Answer

HighScore analytics 0 Answers

Menu gui with background image 0 Answers

Crossfade from menu to the start of the game 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