Simplifying scoring system
Hi,
I would like to simplify my scoring system. For now I got two different score systems which reference to one scoremanager. Other one gives plus points when object is pressed once and minus points when object is pressed second time. Other one vice versa. In all i got two different tests in my game. So I got four score systems. Two of them have reference to scoremanager and two others to scoremanager 1. Is it possible to make this work with just two codes: Score1 and Scoremanager. Here are my codes:
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class Score1 : MonoBehaviour {
public bool ButtonOn = false;
public void Score(int score)
{
ButtonOn = !ButtonOn;
if (ButtonOn)
{
ScoreManager.score += 1;
}
else
{
ScoreManager.score -= 1;
}
}
}
Then I got second one with points vice versa.
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class Score2 : MonoBehaviour {
public bool ButtonOn = false;
public void Score(int score)
{
ButtonOn = !ButtonOn;
if (ButtonOn)
{
ScoreManager.score -= 1;
}
else
{
ScoreManager.score += 1;
}
}
}
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class ScoreManager : MonoBehaviour { public static int score; // The player's score.
Text text; // Reference to the Text component.
void Awake ()
{
// Set up the reference.
text = GetComponent <Text> ();
}
void Update ()
{
// Set the displayed text to be the word "Score" followed by the score value.
text.text = "Score: " + score;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612135007im_/https://answers.unity.com/themes/thub/images/avi.jpg)