• 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 codekidX · Sep 09, 2014 at 03:14 PM · androidjavascript

Need help in creating a Pause Menu[Solved]

Hello guys this game is mainly focusing on Android platform, I have just joined yesterday and started making a game. Although I don't have any programming experience I will try my best to explain my script.

I have a Parent Object named "PauseGame" inside which there are 4 child objects with box colliders namely "PauseMenuBG,resume,exit,levellist"(which are imported images) and these are in a seperate Layer called "Interrupt" which is above default(in which game is being played) and background.

I am using the OnMouseDown function which needs a box collider for resume to work. However the box colliders are affecting the default game layer(images are not rendered but box colliders are still present).

May I know how to remove these colliders on resume button clicked ? And is there any other way to create the pause menu without box colliders?

My resume script is as follows :

 #pragma strict
 
 //perishMenu is for PauseGame parent object
 var perishMenu : GameObject;
 
 function OnMouseDown () {
   //resume game
   Time.timeScale = 1;
   //on click don't render this parent object
   var renderers =  perishMenu.GetComponentsInChildren.<Renderer>();
   
      for (var r : Renderer in renderers)
         {
             r.enabled = false;
         }
     }
 

Solved using my Pause Menu script (Answer :)

 #pragma strict
 
 var isPaused : boolean = false;
 var gameMenu : GameObject;
 var perishCollider : boolean = false;
 var playCollider : GameObject;
 var levelCollider : GameObject;
 var exitCollider : GameObject;
 
 function Start () {
 
        playCollider.collider2D.enabled = perishCollider;
        levelCollider.collider2D.enabled = perishCollider;
        exitCollider.collider2D.enabled = perishCollider;
           //At start don't show the pause menu
       var renderers =  gameMenu.GetComponentsInChildren.<Renderer>();
        for (var r : Renderer in renderers)
         {
             r.enabled = false;
         }
         
         //Always start the game even when exitted using the pause menu
         Time.timeScale = 1;
 
 }
 
 function OnMouseDown () {
    
    //create new variable for the same gameobject 
    var remrenderers =  gameMenu.GetComponentsInChildren.<Renderer>();
     
    //if clicked render pause menu 
    if(!isPaused) {
     
     playCollider.collider2D.enabled = !perishCollider;
     levelCollider.collider2D.enabled = !perishCollider;
     exitCollider.collider2D.enabled = !perishCollider;
     Time.timeScale = 0;
      
      //declare new instance of the pause menu
      for (var a : Renderer in remrenderers)
         {
             a.enabled = true;
         }
     }
     else {
     
     
 
      //don't render on any click(code for safety)
      for (var a : Renderer in remrenderers)
         {
             a.enabled = false;
         }
     
     
     }
    
    }
 










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

0 Replies

· Add your reply
  • Sort: 

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

22 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

Related Questions

game won't work in build 0 Answers

How long should it take me to make my game 2 Answers

Unitron error? 1 Answer

controlling rigidbody 2d 0 Answers

Detecting tag on Android Hittest. 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