Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
MarcoGuy1

Help with pause menu script :(

Question

It keeps turning on automatically and it does not respond when I hit B!

Thanks for taking the time to look at this :)

 

using UnityEngine;
using System.Collections;

public class GunSelectManager : MonoBehaviour
{
    public GameObject pausemenu;
    public GameObject WeaponUI;
    public GameObject WeaponSound;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.B) && pausemenu.active == false);
        {
            pausemenu.SetActive(true);
            WeaponUI.SetActive(false);
            WeaponSound.SetActive(false);
        }
       if (Input.GetKeyDown(KeyCode.B) && pausemenu.active == true);
        {
            pausemenu.SetActive(true);
            WeaponUI.SetActive(false);
            WeaponSound.SetActive(false);
        }
    }
    
}

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 1

You can also shorten that by doing it in one swoop by doing:

 

if(Input.GetKeyDown(KeyCode.B))

{

Bool status = pausemenu.activeSelf;

pauseMenu.SetActive(!status);

WeaponUI.SetActive(status);

WeaponSound.SetActive(status);

}

 

that compares everything with the pause menus original status and sets everything accordingly without the need for an else if statement and whole new block of code

Share this post


Link to post
Share on other sites

  • 0

Please login or register to see this code.

 

Your problem in here. I'm not telling you how to fix it, because it is an easy fix but your problem is there. Look closely at what you either typed or copied and pasted.

Share this post


Link to post
Share on other sites
  • 0

Try this

 

  if (Input.GetKeyDown(KeyCode.B) && pausemenu.active == false);
        {
            pausemenu.SetActive(true);
            WeaponUI.SetActive(false);
            WeaponSound.SetActive(false);
        }
     else if (Input.GetKeyDown(KeyCode.B) && pausemenu.active == true);
        {
            pausemenu.SetActive(true);
            WeaponUI.SetActive(false);
            WeaponSound.SetActive(false);
        }

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...