I am new to game programming. I am working on a game in which user points can be updated by multiple actions (like completing 10 meters, coins collections etc). Can anybody help me what approach can I follow here to update points as there are multiple actions which can update same variable at the same time
Asked
Active
Viewed 57 times
0
-
This question needs more detail. You might also try searching http://gamedev.stackexchange.com/. – DuckMaestro Jun 17 '13 at 04:50
-
Place the score within a static class; dispatch events; use `lock()` if you encounter issues with thread safety. – Jason Sturges Jun 17 '13 at 05:00
1 Answers
1
Usually the overall points and the kind go in a static variable while the level related points are instantiated in the game manager.
The best approach is to make your game manager as a singletone class (see Unity singleton manager classes) and put there a static AddPoints(int) method. That will solve nicely your problem without any concurrence problem because Unity processes the classes and methods sequentially, so it's impossible to have concurrency issues in a class inheriting from MonoBehaviour.

Community
- 1
- 1

Pino De Francesco
- 749
- 5
- 15