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 /
This question was closed Sep 27, 2020 at 03:33 PM by $$anonymous$$ for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by $$anonymous$$ · Jul 07, 2020 at 09:03 PM · time.timescale

Is there any other method to pause a game apart from using Time.timescale=0; ?,Can I pause my game other than setting Time.timeScale = 0;

Hi everyone, I am a 17 yr old novice programmer and have a hard time creating a fully functional pause menu. My issue is that the only thing my code can do is to freeze the time but not the touch input for the player into the game itself. A clearer example is that I can pause the game and nothing moves at all but if I press anywhere else in the game screen apart from the buttons severally and then I resume the game, the player receives all of those inputs (the inputs after tapping many times when it was paused) at once causing it to move uncontrollably and crashes in walls unexpectedly and dies. I don't know if it is possible to disable touch screen functionality (except for the navigation buttons) using code. By the way, the game play moves the player not with buttons but with touch just like Subway Surfers or Angry Birds. Here is the code. I'll appreciate any help I can get. Thanks for your time.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 public class Pause : MonoBehaviour
 {
     public GameObject PauseButton, PausePanel; //References the pause button and pause menu
 
     public void OnPause()
     {
         Time.timeScale = 0;//Freezes time but not game player input
         PauseButton.SetActive(false);//Disables the pause button when game is paused
         PausePanel.SetActive(true);//Enables the pause menu when game is paused
     }
 
     public void OnUnPause()
     {
         Time.timeScale = 1;//Unfreezes time when game is resumed
         PauseButton.SetActive(true); //Re-enables pause button during gameplay after resuming
         PausePanel.SetActive(false);//Disables pause menu
     }
 }
 
 

,Hello everyone. I am a 17-year old novice programmer and having a hard time to pause my game. The issue is that after pressing the pause button on the game screen, the game stops only the time but not user input inside the game. A clearer example is that when I pause the game, I can tap anywhere else on the screen other than the resume button, when I finally press the resume or main menu button to resume, the game receives the multiple touches I had input while it was paused and translates these touches to cause the player to move everywhere as if I have pressed the screen a hundred times at once during gameplay. Is there a way to disable touch input for the game completely (but still enable touch input for the "Resume" and "Back to Main Menu" buttons) when the game is paused so that it won't execute all of those inputs at that moment when I resume the game? I'll appreciate any help.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 public class Pause : MonoBehaviour
 {
     public GameObject PauseButton, PausePanel;  //To reference the Pause button and Pause panel
 
     public void OnPause()
     {
         Time.timeScale = 0;//Freezes time only during pause but game's player still receives input
         PauseButton.SetActive(false);  //Disables the pause button on the screen when game is paused
         PausePanel.SetActive(true);  //Enables the panel which contains the "Resume" and "Main menu" 
     }
 
     public void OnUnPause()
     {
         Time.timeScale = 1; //Unfreezes the game when "Resume" is pressed 
         PauseButton.SetActive(true); //Re-displays the pause button when game resumes 
         PausePanel.SetActive(false); //Disables the pause menu
     }
 }
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

3 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by Slimer37 · Jul 08, 2020 at 06:17 AM

You could try an event system or have your control scripts disable themselves when the game is paused. Maybe you could disable those scripts in that script. They still receive inputs, but since time is frozen, everything it tried happens at once.

Comment
Add comment · Show 2 · 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 $$anonymous$$ · Jul 08, 2020 at 04:18 PM 0
Share

Hey there @Slimer37. That's an awesome idea but I don't know the scripting to do such a task. Can you please help me out with that script. :) I started using Unity last month and don't know much. :(

avatar image Llama_w_2Ls $$anonymous$$ · Aug 27, 2020 at 08:31 AM 0
Share
 public Player$$anonymous$$ovementScript _player$$anonymous$$ovement;
 
 public void Pause()
 {
      Time.timescale = 0;
       _player$$anonymous$$ovement.enabled = false;
 }
 
 public void Resume()
 {
      Time.timescale = 1;
      _player$$anonymous$$ovement.enabled = true;
 }
avatar image
1

Answer by kot2202 · Jul 08, 2020 at 04:38 PM

Disable graphic raycaster component in canvases that control movement

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
1

Answer by sundhar_unity · Aug 27, 2020 at 06:10 AM

https://youtu.be/O_fzjRZWh34

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

Follow this Question

Answers Answers and Comments

131 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

Related Questions

How to get a smoother slow motion 0 Answers

Time.Timescale = 0 in two different places, But there's a delay. 2 Answers

Time.timeScale = 0; freezes my game for a few seconds. 1 Answer

Change Speed of Multiple Objects of the same Class 2 Answers

Pause 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