Hello guys so yesterday i created Play Button which is shown when you finish the level. It works in first scene, but once im redirected to Level 2 and pass the finish line my button script is no longer working.
Here i created global event for enabling play button on finish:
Here I highlighted part of code i want to run when button is clicked.
It is working in first level I play, not in the second one. If I start to play from level 2 its working, but not working in level 3.
Do I need to unsubscribe to those mouse/touch events too?
Hello, of course it is better to see, unfortunately the game is set private for reason and i cant provide inside peeks of the game. If there were only 3 levels iâd not care but there are over 30 levels which somebody can easily copy. But im willing to show you anything related to the button.
When you say âsceneâ do you mean the PlayCanvas scene, or your level, which all are under the same scene?
You also say âcreate global eventâ, then you unsubscribe âglobal eventâ on destroy. Do you subscribe back after you create a new one?
Play Canvas scene = in game Level -> Play Canvas scene 2 = in game Level 2
I think the event is subscribed everytime new scene is Loaded as those events are in initialize and also are in next level, the script with events is in every Scene
Im not sure guys where you heading, play button is attached in inspector which im doing in every scene. context variable is holding âthisâ . it is placed right after initialize:
What I do, and what already is been advised, is to put console.log("number") on all places in the scripts that should be passed. This way you can see in the console of your browser after which number it goes wrong. For example is the step before, the onPress function, called?
Also we can see that onSkipLevel event is passing OK. That takes us in the script where skipLevel is defined.
EDIT3: I think i fixed it, this was part of code before the fix:
and here is after:
I was calling bad event to unsubscribe
And there was event being unsubscribed in delay, dunno why.
Im not sure about one line this changed for context(var context = this), and one line with this without context
Right, so context issues are hard to see from code snippets and require access to debug tools. For example, as you mentioned, context is holding this, however this may point to a different instance of a ScreenTimer script than youâd think.
I read somewhere that you have to wrap this into variable when you wanna use this inside the function. And that is actualy true because back at the day i tried to use this inside the function and it threw me an error, when I wrapped this into variable and used context instead of this then i worked.