I need a help with the score system in my game. Any help will be greatly appreciated.
I have a simple 2d game. This game has two launcher gameobject that launches objects.I have a platform in the middle and one launcher each side.One launches objects after 1 second and other launches after 5 seconds.. I want to add 1 score everytime an object is thrown from the launcher. The script is simple. I added the following script after the object instantiation code.[Note: the script is added in the inspector of both launcher.]
score++; scoreText.text=score.ToString();
So the problem is, the score is updated 1 after one launcher launches object but not added when other launcher launches object. To clarify it simply, the score is updated alternately when object is launched. Need help. Thank you.
Answer by Salmjak · Feb 23, 2016 at 01:38 PM
You need to make your score static between instances of your class.
public static int score = 0;
Static means the value is shared between instances of your class. As it is now both of your launchers have their own score that they add points to.
WOW thank you Salmjak that worked perfectly well. I appreciate your help.
Your answer
Follow this Question
Related Questions
Highscore system unity C# 0 Answers
Simplifying scoring system 0 Answers
How do I get points when clicking an object? 1 Answer
Score tracker adding too many points per jump 0 Answers
How to add and track scoring in online multiplayer with UI? (Unet) 0 Answers