PAUSE MENU in Unity

PAUSE MENU in Unity

Brackeys

6 лет назад

968,905 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@anonymousme3571
@anonymousme3571 - 08.10.2023 17:52

Edit: Managed to get this done. If ya got any qns, drop one here. I'll try to help.

For anyone stuck at the very first step of making the button Tint on hover - go to your "Button" inspector, look for "Navigation". There should be a [Visualise] button, make sure it's not blue. See if that helps.

Ответить
@irarelyupload6930
@irarelyupload6930 - 27.09.2023 23:50

A funny bug I found: if you spam the jump button while paused, you will go flying in the air when you resume hahah. This is easily fixed by disabling the player controller when paused and then enabling when resumed.
Like this: "player.GetComponent<PlayerController>().enabled = false"

Ответить
@solarism5121
@solarism5121 - 27.08.2023 16:58

I just realized he kinda sounds like da vinki

Ответить
@Lightninz49
@Lightninz49 - 23.07.2023 02:44

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class PauseMenu : MonoBehaviour
{
public static bool GameIsPaused = false;

public GameObject pauseMenuUI;

void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (GameIsPaused)
{
Resume();
} else
{
Pause();
}
}
}

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

public void LoadMenu()

{
Time.timeScale = 1f;
SceneManager.LoadScene("Menu");
}

public void QuitGame()
{
Debug.Log("Quitting game...");
Application.Quit();
}
}

Ответить
@pashabezk
@pashabezk - 20.07.2023 16:30

Thank you. This video really helps me

Ответить
@wizard_of_all54
@wizard_of_all54 - 17.07.2023 10:57

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PauseMenu : MonoBehaviour
{
public static bool GameIsPaused = false;
public GameObject pauseMenuUI;

// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (GameIsPaused)
{
Resume();
}
else
{
Pause();
}
}
}

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

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

Ответить
@Seawardsquid397
@Seawardsquid397 - 12.07.2023 06:45

Ok when I click the play button the screen is still there until I click the pause button, it’s a minor inconvenience but how do I fix but this is the only problem every thing else work perfectly fine

Ответить
@dumpling_dev
@dumpling_dev - 30.06.2023 05:30

hey, I'm having an issue where when I start the game the pause menu is there too, like when I play the game the pause menu shows up immediately. I mean I can press escape but I do not want the pause menu to show up every time I load the game :/ If anyone has any advice for this I would greatly appreciate it.

Ответить
@scottgamedev8542
@scottgamedev8542 - 10.06.2023 18:02

if anyone is stuck when they want a different button to load different scenes then replace the LoadScene() function with the code below:

public void LoadMenu(string sceneIndex)
{
Time.timeScale = 1f;
SceneManager.LoadScene(sceneIndex);
}

Ответить
@boyslaye
@boyslaye - 14.05.2023 20:20

FU

Ответить
@frankvolker998
@frankvolker998 - 11.05.2023 14:24

What would be the best way to have the same pause menu for several scenes? (Game level 1, level 2 etc...) making a prefab from the menu canvas? or making an own menu scene and loading with SceneManager additive?

Ответить
@dofyto8622
@dofyto8622 - 09.05.2023 07:48

For those that is having problem with uniteractable button
Make sure your Canvas habe Graphic Raycaster to the setting is default so you don't need to edit it at all
you need to make sure that you give the scene a EventSystem
-RightClick in your project where you usually add text/button
-Then go to UI, EventSystem will be at the bottom of it

Ответить
@owltoe0164
@owltoe0164 - 26.04.2023 04:06

The button is not responding for me

Ответить
@realllllilian
@realllllilian - 18.04.2023 21:50

Hey, i really like your videos and the helped me out a lot, but one question for the guys in the comment section, in my first scene, the pause menu works fine, but when i copy / paste it to other scene, it doesnt work so well
what can i do?

Ответить
@user-zk7ty4ip4q
@user-zk7ty4ip4q - 13.04.2023 22:34

can someone provide the full code of the pause menu please

Ответить
@bumpleGrumpGames
@bumpleGrumpGames - 13.04.2023 09:05

It's mind blowing how Brackeys videos stay relevant and work so well 6 YEARS LATER. Making games is a daunting task but this content has made the learning curve so much smoother! Thank you for sharing so much knowledge with the indie game dev community. 🙏🙏🙏

Ответить
@jaxonhargrove5222
@jaxonhargrove5222 - 12.04.2023 01:12

Whenever i pause my game and the ui shows up, i cant move my mouse. how do i fix this?

Ответить
@jackcard4986
@jackcard4986 - 21.03.2023 22:31

the code just randomly gave me 4 errors

Ответить
@ultimatechato
@ultimatechato - 21.03.2023 01:55

And what happens if I have boolean parameters in my animations, and when I pause the game, they get deactivated?

Ответить
@WOLFRAM_EDITS
@WOLFRAM_EDITS - 08.03.2023 12:43

from 2d to 3d?

Ответить
@thedementedpirate3362
@thedementedpirate3362 - 06.03.2023 15:46

Thank YOU SO MUCH BRACKEY
-Jotaro

Ответить
@Kr1si
@Kr1si - 03.03.2023 18:08

Please someone help i don´t see cursor when i build it but if i play in unity i see it

Ответить
@RF-ww5gc
@RF-ww5gc - 28.02.2023 19:51

in 2023 I see This Turtual
This is increadable 🔥🔥

Ответить
@mohammadgh5768
@mohammadgh5768 - 28.02.2023 12:52

It was great explain

Ответить
@thedogeking7570
@thedogeking7570 - 20.02.2023 01:27

When I load the main menu, the buttons on the main menu stop working, anyone know a fix?

Nvm, just had to unlock the cursor xd

Ответить
@hackgod8802
@hackgod8802 - 19.02.2023 23:52

but how can i make it if i have different levels in my game and they are in different scenes

Ответить
@Demon.Immortalis
@Demon.Immortalis - 19.02.2023 01:26

for the Resume() function use this in the beginning:
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;

for the Pause() function use this in the end:
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;

your welcome ;)

Ответить
@devmarboy4045
@devmarboy4045 - 18.02.2023 05:20

guys if your pause menu isnt working please that the script isnt in the PauseMenu panel because since its disabled scripts inside it wont work or run, so make sure you add the script onto the canvas lol,

Ответить
@Zahard_ph
@Zahard_ph - 10.02.2023 13:33

how to move in planet like this video?

Ответить
@lorenzoaielli4605
@lorenzoaielli4605 - 05.02.2023 17:56

Anyone who can help me? I followed the instructions of the video, and the buttons won't highlight on hovering, nor they'd change color on click. I have an event manager and the buttons are set on interactable. What could the issue be?

Ответить
@reavercleft
@reavercleft - 30.01.2023 14:37

2023 and Brackeys is still saving my arse.

Ответить
@the_allay_4846
@the_allay_4846 - 25.01.2023 04:27

Help there is something wrong. unity is not recognizing my inputs

Ответить
@NotEnvixity
@NotEnvixity - 22.01.2023 18:45

Does anyone know how to make the camera freeze in an FPS game? (I have the timescale set to 0 btw). Would someone be able to help me?

Here's the code if it helps (I don't have a menu, so I left that out):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class PauseMenu : MonoBehaviour


{

public static bool GameIsPaused = false;
public GameObject pauseMenuUI;

// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (GameIsPaused)
{
Resume();
} else
{
Pause();
}
}

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

}

void Pause ()
{
UnlockMouse();
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
GameIsPaused = true;

}

public void QuitGame()
{
Debug.Log ("Quitting Game!");
Application.Quit();
}
void UnlockMouse()
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}


Edit: The movement I'm using is from Unity's First Person preset.

Ответить
@Alexlinnk
@Alexlinnk - 17.01.2023 16:20

Works like a charm

Ответить
@ponedtonever
@ponedtonever - 15.01.2023 00:51

I just figured out if you have:
Cursor.lockState = CursorLockMode.Locked;
in your code, it makes the buttons not react to clicks/hovering.
I feel so stupid but just in case there's anyone else out there with the same problem I have to leave this comment :D

Ответить
@AmzaingCat
@AmzaingCat - 12.01.2023 19:24

does anyone have the same problem as me when you load menu and and load a level, need to press esc twice the first time in order for the pause menu to appear

Ответить
@Markleap
@Markleap - 09.01.2023 22:21

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class PauseMenu : MonoBehaviour
{
public static bool GameIsPaused = false;

public GameObject pauseMenuUI;

void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (GameIsPaused)
{
Resume();
} else
{
Pause();
}
}
}

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

public void LoadMenu()

{
Time.timeScale = 1f;
SceneManager.LoadScene("Menu");
}

public void QuitGame()
{
Debug.Log("Quitting game...");
Application.Quit();
}
}

Ответить
@hodayfa000h
@hodayfa000h - 08.01.2023 20:59

omg i struggled at this one and this is 2d this doesn't help though that is my fault for thinking that it is THAT simple
well i spent a good 2~3 hours researching why and how and what but already i learned new things

Ответить
@freddy_hd_7073
@freddy_hd_7073 - 07.01.2023 21:00

When i press the menu button my particle system in the menu doesn't start. Someone knows hwo to fix it?

Ответить
@reystation4570
@reystation4570 - 31.12.2022 17:26

Hey guys can you help me? I'm creating megaman style game and my problem is when the game paused, the player still can shoot.

Ответить
@safdardeveloper3804
@safdardeveloper3804 - 28.12.2022 16:07

You are the best Unity explainer.

Ответить
@kpcp6974
@kpcp6974 - 01.12.2022 05:21

thank you, so helpful

Ответить
@FriesPG
@FriesPG - 23.11.2022 12:47

I don't have a button only button - text neshg or what

Ответить
@FriesPG
@FriesPG - 23.11.2022 12:39

How do I fix error cs0106?

Ответить
@nathancook8452
@nathancook8452 - 23.11.2022 12:28

Level 1 menus work with the pause and resume however when I create a menu level 2 deep the pause and resume no longer work, even if I used unscaled time for the button.

Ответить
@lachliebreninger2629
@lachliebreninger2629 - 21.11.2022 16:00

its 11:59pm, i started work and 10 am thank you so much for these videos, i don't want to imagine how long it would've taken if i did it cold turkey!

Ответить
@dario.m4707
@dario.m4707 - 12.11.2022 22:54

Does anyone know how to pause the audio while the game is paused

Ответить
@AndreaEvangelista-gj6zy
@AndreaEvangelista-gj6zy - 11.11.2022 22:05

In my 2d game i've implemented this pause menu , but i when click the menu button the particles in the main menu doesn't start even the transition to the game scene (from the menu scenes). Someone can help? Thanks!!

Ответить