There are many ways to skin a cat, and Nebula Games’ way is a perfect solution to this and will definitely give you the result you want. I would just offer another solution, as it’s the way I prefer to work and that is using interfaces.
If you create and store the variable you want to use somewhere, we’ll use game mode for this example. Then create an interface class that has 2 functions in it, I created a simple add currency and remove currency function, and then add that interface to your class that has the variable stored (game mode). You can then just do a simple interface call from any actor you want to alter that variable, say a coin that you pick up.
I used game mode as an example, one because it is a place I like to store game wide variables, but also because you can get a reference to it without having to cast and I like to avoid as much hard referencing as possible. This means the actor that is updating the variable basically doesn’t care what is done with the information, it’s just telling any class that’s listening for the update that it has happened, and they can do with the information what they will.
As I said, the results will be the same, but…
[“The More You Know!”][3]