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 /
  • Help Room /
avatar image
0
Question by Creative Inventory · Aug 28, 2015 at 01:12 PM · not workingpause menu

Pause menu not working!!

I have tried loads of different pause menu scripts, but it doesn't work. My problem is that when the user pause the game the player still moves but really slowly when you tap on the screen. My game is that when ever the user tap on the screen the player moves there, but i want to add a pause menu like flappy birds ( when ever the user tap the pause menu the player won't move towards the pause menu and when the game is paused the player stays locked- like flappy birds) could anyone help?

This is my player movement code:

     using UnityEngine;
     using System.Collections;

     public class PlayerBehaviour : MonoBehaviour {

 public Transform mesh;
 public float forceFly;
 private Animator animatorPlayer;

 private float currentTimeToAnim;
 private bool inAnim = true;
 private GameController gameController;

 // Use this for initialization
 void Start () {
     animatorPlayer = mesh.GetComponent<Animator>();
     gameController = FindObjectOfType(typeof(GameController)) as GameController;
 }
 
 // Update is called once per frame
 void Update () {

     if(Input.GetMouseButtonDown(0) && gameController.GetCurrentState() == GameStates.INGAME && 
        gameController.GetCurrentState() != GameStates.GAMEOVER){

         inAnim = true;

         GetComponent<Rigidbody2D>().velocity = Vector2.zero;
         GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 1)*forceFly);

         SoundController.PlaySound(soundsGame.wing);

     }
     else if(Input.GetMouseButtonDown(0) && gameController.GetCurrentState() == GameStates.TUTORIAL){
         if(gameController.CanPlay()){
             Restart();
         }
     }

     animatorPlayer.SetBool("callFly", inAnim);

     Vector3 positionPlayer = transform.position;

     if(positionPlayer.y > 5){
         positionPlayer.y = 5;
         transform.position = positionPlayer;
     }

     if(gameController.GetCurrentState() == GameStates.TUTORIAL){
         inAnim = true;
     }

     if(gameController.GetCurrentState() != GameStates.INGAME && 
        gameController.GetCurrentState() != GameStates.GAMEOVER){
         GetComponent<Rigidbody2D>().gravityScale = 0;
         return;
     }
     else{
         GetComponent<Rigidbody2D>().gravityScale = 1;
     }

     if(inAnim && gameController.GetCurrentState() != GameStates.TUTORIAL){
         currentTimeToAnim += Time.deltaTime;

         if(currentTimeToAnim > 0.4f){
             currentTimeToAnim = 0;
             inAnim = false;

         }
     }




     if(gameController.GetCurrentState() == GameStates.INGAME){


         if(GetComponent<Rigidbody2D>().velocity.y < 0){
             mesh.eulerAngles -= new Vector3(0,0,5f);
             if(mesh.eulerAngles.z < 270 && mesh.eulerAngles.z > 30)
                 mesh.eulerAngles = new Vector3(0,0,270);
         }
         else if(GetComponent<Rigidbody2D>().velocity.y > 0){
             mesh.eulerAngles += new Vector3(0,0,2f);

             if(mesh.eulerAngles.z > 30)
                 mesh.eulerAngles = new Vector3(0,0,30);
         }

     }
     else if(gameController.GetCurrentState() == GameStates.GAMEOVER){
         mesh.eulerAngles -= new Vector3(0,0,5f);
         if(mesh.eulerAngles.z < 270 && mesh.eulerAngles.z > 30)
             mesh.eulerAngles = new Vector3(0,0,270);
     }
 
 }

 void OnCollisionEnter2D(Collision2D coll) {
         gameController.CallGameOver();    
 }    

 void OnTriggerEnter2D(Collider2D coll) {
         gameController.CallGameOver();    
 }

 public void RestartRotation(){
     mesh.eulerAngles = new Vector3(0,0,0);
 }

 public void Restart(){
     if(gameController.GetCurrentState() != GameStates.GAMEOVER){
         gameController.ResetGame();
         gameController.StartGame();
     }
 }
 

}

Comment
Add comment · Show 4
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 Dave-Carlile · Aug 28, 2015 at 01:17 PM 0
Share

But where is your pause menu code? :)

avatar image Creative Inventory · Aug 28, 2015 at 01:58 PM 0
Share

Okay i solve most of the problem, the only thing is that how do i make my player not to move towards the pause button when i click pause?

avatar image Dave-Carlile · Aug 28, 2015 at 03:42 PM 0
Share

You can use EventSystem.IsPointerOverGameObject to ignore input that goes to the UI.

avatar image Creative Inventory · Aug 28, 2015 at 06:26 PM 0
Share

Could you please explain this in more detail please? I took a look at the link but I really didn't understand it that much.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mackhack2015 · Dec 03, 2018 at 01:21 PM

 public void Resume()
     {
         pauseMenuUI.SetActive(false);
         Time.timeScale = 1f;
         GameIsPaused = false;
 
 
     }
 
     void Pause()
     {
 
         pauseMenuUI.SetActive(true);
         Time.timeScale = 0f;
         GameIsPaused = true;
 
 
             
     
 
     }


Have you tried Time.timeScale?

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 mackhack2015 · Dec 03, 2018 at 01:22 PM 0
Share

I can tell you about the functions and how they work if need be.

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

29 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

Related Questions

Pause Menu not showing 1 Answer

Touch detecting not working with Google Cardboard. 2 Answers

How to Add time to my timer on colliding 1 Answer

Why isn't my pistol colliding with the wall? 1 Answer

Inconsistent input detection across different computers 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