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 /
avatar image
0
Question by Starbound Explorer. · Apr 16, 2015 at 03:50 PM · c#ui

Pause Menu?

So after watching a video I think I understand how this code should work and setactive does not turn off my pause menu I have the pauseUI selected as the object rigged to the main camera and nothing happens perhaps the tutorial I was watching is outdated or it's because I have more then one scene? My problem isn't with stopping time it's with setting my canvas to false so that I don't have a pause menu in the middle of my screen. This is my first project in unity so I don't really understand much in terms of programming.

So it turns out the weirdest fix I've done was changing my void's to FixedUpdate save then change it back... I don't know what caused it to work or if my void's weren't right before but it's working.

using UnityEngine; using System.Collections; using UnityEngine.UI; public class Pause : MonoBehaviour { public GameObject pauseUI; private bool paused = false; void Start(){ pauseUI.SetActive(paused); } void Update(){

     if (Input.GetButtonDown ("Pause")) {
         paused = true;
     }
     if (paused == true) { 
         pauseUI.SetActive (true);
         Time.timeScale = 0.0f;
     }
     if (paused == false){ 
     
     pauseUI.SetActive (false);
     Time.timeScale = 1;
         Debug.Log ("I am Working");
 }

} }

Comment
Add comment · Show 3
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 cariaga · Apr 16, 2015 at 04:46 PM 0
Share

you stopped time completely you should set

  Time.timeScale = 0.01F; ins$$anonymous$$d of  Time.timeScale = 0;

avatar image KdRWaylander · Apr 17, 2015 at 07:35 AM 0
Share

If you wanna work with UI you should use

 using UnityEngine.UI;

and then

 public Canvas pauseUI;

It will be easier to access the methods/functions, you won't have to add GetComponent() everywhere ^^ If you wanna reduce a little bit your code you could do

 pauseUI.SetActive(paused);

which would save you the if statement, but since in this case you have multiple operations in your if, it's okay like that.

And yes, remember to add an 'f' at the end of your floats values ;)

avatar image Nomibuilder · Apr 18, 2015 at 07:05 AM 1
Share

Where are you setting your pasued boolean false? I Couldn't see it in your code.

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Nomibuilder · Apr 18, 2015 at 07:09 AM

Check your Start() Function it should be Like.

 Start()
 {
 paused = false;
 }

Instead of

 Start()
 {
 pauseUI.SetActive(paused);
 }



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
0

Answer by Erathor · Apr 17, 2015 at 07:10 AM

yes and look if u have any other scripts where u use the Time.timeScale

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
0

Answer by Starbound Explorer. · Apr 17, 2015 at 10:18 PM

I have a spawning script that uses Time.Deltatime does that count? and sorry about the poor coding I legitimately just copied this off a tutorial I'm going to show an edited version of the code that just throws a bunch of errors from trying to change it to a public canvas it has to be a gameobject for setactive to work

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 Nomibuilder · Apr 18, 2015 at 07:01 AM 1
Share

Put it in comment. This is not an answer.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer

NullReferenceException: Object reference not set to an instance of an object 1 Answer

How to have both, a scroll view AND vertical Layout? 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