#private void Update()
1 messages · Page 1 of 1 (latest)
Does this work aswell?
if (gameManager != null)
{
if (gameManager.GameIsPaused)
{
UpdateCursorLockState(CursorLockState.Confined);
}
else
{
UpdateCursorLockState(CursorLockState.Locked);
}
}
if you have another if statement now you had like 3 brackets
Yeah it works
i always prefer escaping the function instead
guess it's personal preference
Yeah I get less errors live
IT run before
How did u fix it
I see
once you go with events you never go back
I understand
How would that work as for this case?
I'm really trying to get that build out to my friend today
basically you just subscribe to the Gamemanager static event
Sounds easy
public static event Action<bool> OnGameIsPaused
put that inside your game manager
then to call it when you pause
OnGameIsPaused?.Invoke(thePausedBool)
? is a null check
I see
if no listeners, then it spits out null if you try invoke it
Yeah recently learned about x ??= y
yeah
then inside any class you want to listen to event "Subscribe"
like you do for any notifications in real life like youtube
OnEnable(){
GameManager.OnGameIsPaused += TheMethodWhenGamePaused; }```
I see like an input action
private void TheMethodWhenGamePaused(bool isPaused)
if(isPaused) // do something```
basically
yea events
OnDisable(){
GameManager.OnGameIsPaused -= TheMethodWhenGamePaused; }``` to clean up
now u dont need to check every frame in Update
calling game manager instance is safe in enable? (even when having the script order right)
you're not calling Instance
notice I put static
this means this event belongs to the class itself
here
oh
yeah exactly
thats not Instance
you're using the event directly on the class
its static , so only 1 exists
and belongs to the class, not the instance
same reason you can write GameManager.instance
I see
instance is a static
So how does my cursor handler know when the event is invoked?
Ah wait I understand
nvm
THIS IS GREAT
got it workin?
just a sec
cleanin up
Coding is cool
Okay building rn
Scripts stop compiling when timescale is set to 0 right?
True I couldnt unpause then xD
makes sense
thats why we multiply movement by fixed delta time
where do you do the unpausing
I press ESC as an input action and the game manager does it
no fixedDelta time is to keep things framerate independent but inside FixedUpdate
show how you wrote the gameManager part
ok wat about the script that doesnt work
That doesnt work
I can send u the other one too
but the UI Element is not displayed
trying to find out why
(it works in editor)
send the one that isnt doing the thing
This is the one receiving the message
And then I have this one with another nullpointer problem in line 32
https://paste.ofcode.org/s8Q6FjpqTifcm5vWb9np2s
When those 3 are working I can finally build and send it to my friend
Let me implement another event for the line 32
which part of this one doesnt work
I send that one bcs its the one needing the variable from the game manager, I thought you wanted to see that one?
Also sorry for the messy code. I usually comment the important and less important parts
Yeah
which part doesn't work you said
lemme see
and is the Object this script is on Active the whole time ?
CursorHandler
CursorHandler I mean
ok
wait no
well yes
in this build
I plan to implement something at a later point that will deactivate the gameobject
one thing at a time
But thats for another time
Yes
Okay the only problem left is RenderHelper.cs:38
let me implement an event and look for other problems
can fix this one myself because I learned from the best
oml no errors
Thank you so much for your time!
Pause isnt working tho 
huh? what part isnt working exactly
It's not doing it
No pause
It's not setting timescale to 0
not muting my audio sources
and not displaying my pause UI
It does in the editor
but not my development build
do you have any errors?
Nope
put Debug logs make sure its runing
Neither editor nor build
sure
Do I see debug chat in the dev build=
?*
it should
lets see
i also use this sometimes
https://assetstore.unity.com/packages/tools/gui/in-game-debug-console-68068
On it
Just a prefab into the scene? Easy
Nice
I guess something is still not working
oh nvm it's the prefab looking for an eventsystem handler
private void Start()
{
Debug.Log("Log");
Debug.LogWarning("Warning");
Debug.LogError("Error");
}
This is not showing
huhh
Meaning the object is not there??
How
hmm are you sure you are exporting the correct scene
yes I only have 3 scenes
This is definetely the one I have here
I have a main menu 2D
This one open world
And a third (empty) one for testing stuff
strange, is the gameobject that script is on enabeld
Yup
It works in the editor
I see the debug log in the editor
I restart and try again
IT WORKS IN A NORMAL BUILD HUHH
OKay well ggs
I guess dev build messes stuff up?