After implementing Singleton pattern, how to set different points?

Since the Game Status becomes Singleton, how can we set pointsPerBlockDestroyed differently in each scene?

Should I take the pointsPerBlockDestroyed from Game Status and put it into another set of gameObject and script?

Hi,

In your GameStatus object, you could check in which level you are and determine how much points each block is supposed to give.

However, it would probably make more sense to define the points in the Block object because the block provides the points.

That’s a design decision, though.


See also:

Thanks for suggestion.

I have tried two methods but failed.

  1. Create an independent gameObject and script for PointsPerBlockDestoryed, and refer to them in Game Status. However, Game Status always sticks to the value from the first scene.
  2. Put the PointsPerBlockDestoryed inside Block.cs and create a GetPoints() method. Then, I call the method inside Game Status AddToScore() method. However, the value still sticks to the value from the Block in the first scene.

Anyway, how should I excite your first suggestion about checking in which level? Should I get the Scene number as use conditional statement inside AddToScore() method?

Either the build index or the name of the scene. Check the Scene class in the API. It contains all the information you need. And then you create a bunch of if-statements or a switch to define what is supposed to happen in specific scenes.

I used conditional statement with scene build index to determine PointsPerBlockDestoryed, everything works fine, and the process reinforced my learning. Thank you so much!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms