In a 1v1 score system I made, the value of both scores should go down to 0 if one side reaches 5, but it only works with one side. I’m fairly new to c#, so I dont know if this is a good way to do it. would appreciate any help!
This Code Doesnt Work:
{
public GameObject Player2Score;
public static int ScoreValue = 0;
Text score;
void Start()
{
score = GetComponent<Text>();
GameObject.Find("Player1Score");
}
void Update()
{
score.text = "" + ScoreValue;
if (ScoreValue >= 5)
{
ScoreValue = 0;
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
if (ScoreScript2.ScoreValue2 == 5)
{
ScoreValue = 0;
}
}
}
This Code does
{
public GameObject Player1Score;
public static int ScoreValue2 = 0;
Text score;
void Start()
{
score = GetComponent<Text>();
GameObject.Find("Player2Score");
}
void Update()
{
score.text = "" + ScoreValue2;
if (ScoreValue2 >= 5)
{
ScoreValue2 = 0;
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 2);
}
if (ScoreScript.ScoreValue >= 5)
{
ScoreValue2 = 0;
}
}
}
Point Adder:
{
private void OnTriggerEnter2D(Collider2D collision)
{
ScoreScript2.ScoreValue2 += 1;
SceneManager.LoadScene("MainGame");
}
}
Other Point Adder:
{
private void OnTriggerEnter2D(Collider2D collision)
{
ScoreScript.ScoreValue += 1;
SceneManager.LoadScene("MainGame");
}
}
Not sure where I went wrong, because I think that both codes are the exact same apart from the class and Integer names.