Hey everyone,
Going back over this to help my students get a working lives system setup. What I have so far is the following. It’s in the LoseCollider script. I can’t figure out how to reset the Ball at this point. I’ve tried grabbing the object and manipulating the transform to no avail. Any ideas?:
Yeah resetting the position is my problem. Reading my own code, I am unclear how exactly the position of the ball was set. It seems like I set it by hand and constrained it from there. That seems to present a problem.
That’s correct. In the lectures you positioned the Ball game object by hand. So, you could consider viewing the position in the Ball’s transform, and placing this in code instead. You could consider adding this as a method to your LevelManager which is actually called at the start of the game also, thus, reuse. Be sure to reset the PaddleToBallVector also.
Never mind. I’m an idiot and had two ball gameobjects in my hierarchy. That seems to be working. I’m getting a nullreference exception from my LevelManager I need to track down. Thank you so much @Rob and @Galandil
If you find yourself checking for more than just the Ball, and the logic starts getting quite complex, you may find determining at the beginning of the game initialisation which scenes are playable and which are not useful.
For example, you know that Start, Lose, Win (the named scenes) are not playable.
So you could pop the non-playable scene names into an array and then, on loading the scene, check to see if the scene that has loaded is in fact a playable scene or not based upon its name being contained in that array.
The result of this check could then be set in a flag of Type bool, e.g. bool sceneIsPlayable.
Then, all of your logic around what should/shouldn’t appear or happen within that scene can be based around that variable.
That’s solid information! I may give it a try. I’m considering rebuilding some or all of this game from the ground up with a potentially more streamlined scripting system. We will see if I have the time. Thanks again @Rob.
That sounds like a great idea, not because you necessarily need to, to have a playable game, but by rebuilding it you will invariably find that, now you have a complete working game that you understand, you are in a much better position to redesign / restructure it’s architecture.
When you find yourself saying “should this really be in the lose collider” or, “should the ball really know about the player’s lives” etc, jot those down, either on paper, or as comments in the code with a “TODO:” in front of them, if you are wondering about these at any point it may suggest that something isn’t quite right and that it needs a little further consideration.