#private void Update()

1 messages · Page 1 of 1 (latest)

digital steeple
#

Does this work aswell?

if (gameManager != null)
{
    if (gameManager.GameIsPaused)
    {
        UpdateCursorLockState(CursorLockState.Confined);
    }
    else
    {
        UpdateCursorLockState(CursorLockState.Locked);
    }
}
eternal raptor
#

eh nested if statements

#

but sure

digital steeple
#

xD

#

It's fine aslong it's 2 max 3

#

imo

eternal raptor
#

if you have another if statement now you had like 3 brackets

digital steeple
#

Yeah it works

eternal raptor
#

i always prefer escaping the function instead

digital steeple
#

So it's not assigned

#

why tf not

eternal raptor
#

yup

#

is it running at all ?

#

like after

digital steeple
#

Yeah I get less errors live

#

IT run before

eternal raptor
#

ok so ordering issue

#

I had that happen before

digital steeple
#

How did u fix it

eternal raptor
#

I generally don't have things polling in Update

#

everything is event based for me

digital steeple
#

I see

eternal raptor
#

once you go with events you never go back

digital steeple
#

I understand

#

How would that work as for this case?

#

I'm really trying to get that build out to my friend today

eternal raptor
#

basically you just subscribe to the Gamemanager static event

digital steeple
#

Sounds easy

eternal raptor
#

public static event Action<bool> OnGameIsPaused

digital steeple
#

dont know much about events

#

Okay I'm writing 🖋️

eternal raptor
#

put that inside your game manager

#

then to call it when you pause

#

OnGameIsPaused?.Invoke(thePausedBool)

#

? is a null check

digital steeple
#

I see

eternal raptor
#

if no listeners, then it spits out null if you try invoke it

digital steeple
#

Yeah recently learned about x ??= y

eternal raptor
#

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; }```
digital steeple
#

I see like an input action

eternal raptor
#
private void TheMethodWhenGamePaused(bool isPaused)
if(isPaused) // do something```
eternal raptor
#

yea events

#
OnDisable(){
GameManager.OnGameIsPaused -= TheMethodWhenGamePaused; }``` to clean up
#

now u dont need to check every frame in Update

digital steeple
#

calling game manager instance is safe in enable? (even when having the script order right)

eternal raptor
#

you're not calling Instance

#

notice I put static

#

this means this event belongs to the class itself

eternal raptor
#

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

digital steeple
#

I see

eternal raptor
#

instance is a static

digital steeple
#

So how does my cursor handler know when the event is invoked?

#

Ah wait I understand

#

nvm

#

THIS IS GREAT

eternal raptor
#

got it workin?

digital steeple
#

just a sec

#

cleanin up

#

Coding is cool

#

Okay building rn

#

Scripts stop compiling when timescale is set to 0 right?

eternal raptor
#

no

#

the only thing that stops with timescale are things depending on time

digital steeple
#

True I couldnt unpause then xD

#

makes sense

#

thats why we multiply movement by fixed delta time

eternal raptor
digital steeple
#

I press ESC as an input action and the game manager does it

eternal raptor
eternal raptor
digital steeple
#

(It's not working)

#

I dont get the UI Obejct

#

active

eternal raptor
digital steeple
#

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)

eternal raptor
digital steeple
#

This is the one receiving the message

#

When those 3 are working I can finally build and send it to my friend

digital steeple
eternal raptor
digital steeple
#

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

eternal raptor
#

CursorHandler

#

im talking about this one

digital steeple
#

Yeah

eternal raptor
#

which part doesn't work you said

digital steeple
#

lemme see

eternal raptor
#

and is the Object this script is on Active the whole time ?

digital steeple
#

Which one?

#

Script handler yes

eternal raptor
#

CursorHandler

digital steeple
#

CursorHandler I mean

eternal raptor
#

ok

digital steeple
#

wait no

#

well yes

#

in this build

#

I plan to implement something at a later point that will deactivate the gameobject

eternal raptor
#

one thing at a time

digital steeple
#

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!

digital steeple
eternal raptor
digital steeple
#

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

eternal raptor
#

do you have any errors?

digital steeple
#

Nope

eternal raptor
#

put Debug logs make sure its runing

digital steeple
#

Neither editor nor build

digital steeple
#

Do I see debug chat in the dev build=

#

?*

eternal raptor
#

it should

digital steeple
#

lets see

eternal raptor
digital steeple
#

Okay either I dont see em

#

Or They dont work

#

They do in the editor as I said

eternal raptor
#

maybe try the asset

#

g2g to work in 7 mins

digital steeple
#

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

eternal raptor
#

hmm are you sure you are exporting the correct scene

digital steeple
#

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

eternal raptor
#

strange, is the gameobject that script is on enabeld

digital steeple
#

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?

eternal raptor
#

either that or it kept exporting an old build

#

sometimes is good to do a Clean build

digital steeple
#

Ahh I see

#

well I did restart the editor