I don’t know what I changed, but all of a sudden the blocks refuse to break if there’s been a game over screen and I choose to play again. I’m looking all over for inconsistencies and comparing them to the code in the lessons, and I’m at a loss. Any ideas? Anyone experience this?
Hi! Welcome to the community!
First go and check if the collision is triggering, add a debug line to your Block code, you can go from there, but this is going to be a little hard to track down.
If the collisions are sending the debug message then you are missing a component tied to that behavior, you’ll have to check every script related to the Blocks breaking behavior, not just for code errors but editor errors, like scripts missing after you reload a level, I’ve seen those sort of errors before where people forget to add a script and cause this sort of weird bug.
If you want, I can take a look at your project, just create a Unity Package (Assets > Export Package… > Export), upload it somewhere like Dropbox or Google Drive, and paste a download link here so I can check what is causing your issue.
I know, it’s a web of scripts and interactions and I’m just not good enough (yet?) to find the spot that’s making it act up. I’d really appreciate you taking a look, thank you so much for the offer
Here’s the google drive link: https://drive.google.com/file/d/1UJ5VW0Eqoxe6d7XWHiK41C0EaWuGTGks/view?usp=sharing
Edit: I did just add in some debug lines and it is colliding and making its way through the Destroy() section of the DestroyBlock() method, but the blocks aren’t disappearing. Thanks again for taking a look!
I managed to fix your issue but… There’s something weird going on, if the player doesn’t launch the ball the game will trigger the Game Over screen, I found out why that is happening but have no idea on how to solve it, I’ll be back as soon as I solve that issue.
Ok, solved everything.
Your GameStatus
game object loses the reference to the Text object after loading scenes, this will prevent your game from working correctly, if you add a third level it will stop working without even going to the Game Over screen.
- How to solve this? You can do one of three things:
-
Child your
Game Canvas
object to yourGameStatus
object. This will prevent the reference from being lost when another screen loads, but there’s an issue with that, the score will always show regardless of the screen. -
Remove your
GameStatus
game object and add the "GameStatus`script to the Canvas. This has the same issue as the one above. -
Get the reference of the Text Object when loading a new scene, this will require a bit of coding. That can be a great challenge, but if you don’t feel like doing that you can do just well with the first solution.
-
The Game Over screen triggers after not launching the ball for a short period of time. This is caused due to gravity, the solution is quite simple. Set the Ball’s Rigidbody’s gravity setting to 0, if you want the ball to react to gravity you’ll have to activate it when launching the ball, to do that you just have to add a line of code to your LaunchOnMouseClick
method;
GetComponent<Rigidbody2D>().gravityScale = 1;
Hope this helps!
Thank you! I don’t think there’s really an issue with the score displaying, since the one place it shouldn’t be is the start menu, which doesn’t need the GameStatus prefab. I hadn’t actually encountered the issue with game over after a few seconds weirdly enough, so I’m not sure why that’s the case. I added the gravity code just in case it’s a Mac/pc, unity version issue or something.
Anyway, that worked so thank you so much for all your help, I really appreciate it.
This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.