• 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
Question by Brijac · Dec 07, 2020 at 02:13 PM · scene loadpause game

Pause game automatically on scene start and then resume on key press

So, I don't want my game to start immediately when the scene loads, I want my game to be paused from the start and then resumed on Space key pressed.

So, scene loads, game is paused, panel (on w$$anonymous$$ch there is text like "press Space button to start") is active and then when the player presses Space the game should resume, panel (on w$$anonymous$$ch there is text like "press Space button to start") should become inactive and audio of the game should start playing. How can I do t$$anonymous$$s?

T$$anonymous$$s is what I did:

Created t$$anonymous$$s script and put it on that panel that is active in the beginning:

 public class SceneStartPause : MonoBehaviour
 {
     public GameObject SceneStart;
     private void Start()
     {
         Time.timeScale = 0;
         SceneStart.SetActive(true);
     }
     public void OnSceneStart()
     {
         if (Input.GetKeyDown(KeyCode.Space))
         {
             Time.timeScale = 1;
             SceneStart.SetActive(false);
         }
     }
 }

The panel is active and game is paused on scene start but not$$anonymous$$ng happens when I press the Space button, why is that? Also how could I add audio to start playing when the Space button is pressed?

Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by qsp18 · Dec 07, 2020 at 02:50 PM

Put in the start method: void Start() { time.timescale = 0; }

and then in update function void Update() { if (Input.anyKey) { time.timescale = 1; } }

Comment
Brijac

People who like this

1 Show 3 · 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 Brijac · Dec 07, 2020 at 02:54 PM 0
Share

It worked, I made stupid mistake by not simply using Update..

Do you maybe know how can I also make audio play when the key is pressed?

avatar image qsp18 Brijac · Dec 07, 2020 at 04:02 PM 0
Share

Add an AudioSource-Component to your Object. Check the "Loop" Box, if you want audio to be constantly played. When you put your timescale to 1, just GetComponent().Play()

avatar image qsp18 · Dec 07, 2020 at 04:04 PM 0
Share

To have better Performance, you can even start a coroutine to check, if any key is pressed and then yield break the IEnumerator if it is pressed.

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

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

How to make a pause menu with Gui Texture?? 2 Answers

I want OnClick to fire the same frame that the button is clicked 1 Answer

How do I unpause my game using Time.timeScale? 1 Answer

Working example of loading scene as asset bundle in Android!? 0 Answers

Duplicate scene via script,Saving virtual World 2D 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