Pop up panel after all 4 counters reach the number 10. This is what I have so far.
I cannot figure out how to get the score connected to the scoreText
How do I do this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class NextLevelColors : MonoBehaviour
{
public int score;
public Text scoreText;
public GameObject gameOverPanel;
void Update ()
{
for (int i = 0; i < score; i++)
{
if(i > 9)
{
gameOverPanel = null;
}
else
{
gameOverPanel.SetActive(true);
}
}
scoreText.text = score.ToString ();
if (score >= 9)
{
gameOverPanel.SetActive(true);
}
}
}
Hello!
First, this line:
gameOverPanel = null;
is making the variable gameOverPanel to become null, you are not disabling the panel, you are just “deleting” the variable link to the gameobject. I supose you mean to do is:
gameOverPanel.SetActive(false);
Second, you want to do something when 4 conditions are true, so you need to do something like:
if(score1>=9 && score2 >= 9 && score3>=9 && score4>=9)
{
something
}
else
{
something else
}
Bye!
Thank you for your help. I am new at codding. I have added somethings but am still unsure of how to connect the score to all of the score texts.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class NextLevelColors : MonoBehaviour
{
public int score;
public int score1;
public int score2;
public int score3;
public int score4;
public Text scoreText1;
public Text scoreText2;
public Text scoreText3;
public Text scoreText4;
public GameObject gameOverPanel;
void Update ()
{
for (int i = 0; i < score; i++)
{
if(score1>=9 && score2>=9 && score3>=9 && score4>=9)
{
gameOverPanel.SetActive(true);
}
else
{
gameOverPanel.SetActive(false);
}
}
}
}