#Pause
1 messages · Page 1 of 1 (latest)
ok
why is this there
public static Pause pause
also don't name your classes lowercase
ah nevermind that, it's nothing
classes should always be PascalCase
capitalize the first letter always
anyway ok You added the event here. You just have to Invoke it when you pause with the appropriate value
also you should probably store the state inside a bool
#💻┃code-beginner message like for example this?
link isn't going anywhere
what?
why are you sending me this
is this an example of invoke?
I just told you the Link isn't working
what dont you get lol
first store the bool of isPaused
It took me to Fens example code where they invoke
ohh thats weird, mine just takes me to this thread
private bool isPaused;?
that would be a boolean yes
when i click on the thread, it takes me to Fens example code
ok, i added it
correct
now you have to Invoke that value on the event
any time it changes to a new value
like Invoke("PauseGame")?
no
Monobehavior.Invoke
and event.Invoke are completely different
You have to Invoke the value on the event
do you see OnGamePaused passes a bool value around
yeah
So invoke this event with the bool value, when the value changes
OnGamePaused?.Invoke(paused);?
is your bool named paused
I mean isPaused
hmmmmm.... in.... PauseGame?
is PauseGame the only time isPaused changes ?
You dont want to track it when its not paused?
PauseGame and ResumeGame changes because PauseGame have true and ResumeGame and false
right so based on that, I ask again. Where do you think should put the invoke you showed
not so hard is it ?
ok, now let me test it
wait
part 1 is done
you still didn't do the second part
You are "Broadcasting" this Event
but is anyone that cares listening ?
huh? second part?
yes.
You only announced the event
but something needs to "listen" to this event
dont you want to do something with isPaused ?
in another script
back to Player2D script?
that would be one of them interested in that bool, sure
ok, I am back in the Player2D script
moving -= !paused; or pause.OnGamePaused -= HandlePause;?
so basically
in awake Subscribe +=
and in OnDestroy -= UnSubscribe
or you can do OnEnable +=
and OnDisable -=
thats what I typically do
the same way you wrote the += one but -=
think of it like Youtube or Twitch or anything that has Subscribers
+= means you are SUBSCRIBING to the events
-= means you are NOT-SUBSCRIBING to the events anymore
its good practice to cleanup subscribing especially when object gets destroyed, we don't keep subscribed to something that is destroyed
so like... should i put pause.OnGamePaused -= HandlePause; in..... ? since pause.OnGamePaused += HandlePause; is in void awake
I said it already, also said another option #1246134682991460352 message
read carefully the first one
maybe that to make sure player is not moving no matter what button you press?
what?
that doesnt explain what i asked
where in the script do you flip player left/right
so how the hell do you expect the event to affect this at all
com on
simple logic
you are changing moving bool. What does moving bool do.
again
that moving is that when the player moves like jumping, attacking, flipping sides and if it's set to false the player unable to do any of this stuff
let me see it
in the code
that moving is that when the player moves like jumping, attacking, flipping sides and if it's set to false the player unable to do any of this stuff
but where?
its literally not doing anything
just receiving the value
idk, I got the example from fren
its not affecting any other code at all
You need to start applying the examples to make sense
thats why they are examples
obviously its not doing anything in your code how could it possibly affect it?
you should know this by now..
OK make this very simple
is Player2D supposed to do ANYTHING while paused
no
GetComponent<Player2D>().enabled = false in Pause Game and GetComponent<Player2D>().enabled = true in ResumeGame?
do you have another scripts that has bother player2d scripts referenced?
no?
I mean
the scripts the player have is muon interaction, scroll interaction, hitpoints, player components, player projectile
anyway thats fine
since you know how to disable it just use that instead
all MonoB scripts have the enabled
so link the enabled to the value from event
inside HandlePause
all the scripts?
like this?
is this inside Player2D why are you doing GetComponent
also why you hardcoded false 🤔
which script is this?
Player2D
HandlePause is inside Player2D ?
yes
then you don't need GetComponent, since you already are In the component you need
The this keyword is for self referencing. this.enabled
its implied you don't really need it
And yeah, instead of false, use the bool you are passing in
Yeah true, I always tend towards overly explicit haha
if you had another variable named enabled in a method parameter then yea
i use this often when my method parameter has the same name as my fields
idk wha tto write in HandlePause
you want the script to disable, you know what enabled does? what do you think
adhd moment
try a little more so I don't have to spoon feed you every line
Handle Pause is giving you the Value of the Paused event
enabled property determines if script is enabled or not
its a 2+2 moment
but even if the Player2D is disable, this script line that is inside Player2D script would also be disable, won't it?
no because it still subscribed to the event
enabled only disables Unity specific events
like Update
Only Disabling a GAMEOBJECT would prevent any lines from running
wtf is going on here
you literally overcomplicated the shit out of this
enabled needs to be set with a value.. do you not see its red?
think for a moment how the flow goes
HandlePause gets paused from the event OnGamePaused
what do you think you should do with paused
As nav said, remove the entire line at 101. You are IN that component, no need to get it.
Then the other line of course needs.... an =, right?
You can's just tell the compiler "enabled"
You want to tell it "set enabled to [true/false]"
Ah, that's what I get for jumping in and out. Yeah, the getcomponent is for the other script
Its not like they dont know how to assign values thats whats most 
@warped pumice Did you get it working?
wait
About to run out
huh?
I have to run to work 😛
Look here
what do you think goes on the Red line
its an easy test
based on everything me and Aethenosity wrote
the player is not moving when pausing, so it's working
yeah, man I have autism and ADHD that is a big disadvantage for me to understand all coding, especially i always forget
Yeah I mean, have adhd as well so I can understand, but really repetition is key, you haven't practiced what you learned enough you're gonna forget if you don't instill it
doing something once or twice isnt enough
I literally had to do it for years before it really becomes muscle memory
also have big memory problems from injury so believe me, If I can do it so can you lol
just practice what you learned, if you learned about event. Do it in other projects or use it more, keep practicing until it make sense
The MAJOR benefit of the Event , also called the Observer pattern. Is your Pause Script doesn't care about Player scripts or anything, it just says "I was paused/unpaused"
other scripts that listen to that Event react in their own way, in your case Player2D script disables itself etc.
it can be used for other use cases, you don't have to put a dozen references in the Pause script when it doesn't need to
By implementing common game programming design patterns in your Unity project, you can efficiently build and maintain a clean, organized, and readable codebase. Design patterns not only reduce refactoring and the time spent testing, but they also speed up onboarding and development processes, contributing to a solid foundation that can be used t...
Very important to learn these concepts ^^

