Hello guys, i need some help please!
So in my game i have a you lose panel, that apears when you die, in editor everything is fine, but in the apk when the game start, the panel already start active, and the button restart doesnt work, so i really dont know whats happening, im going to post my code above so you guys can help me.
public class GameManager : MonoBehaviour
{
public GameObject[] uiElementos;
public GameObject container1;
//SpawnJason
//
public static GameManager instance;
public bool gameOver;
//[SerializeField]
private GameObject youLosePanel;
//[SerializeField]
private Button denovo;
public bool jogoComecou;
//public GameObject[] uiElementos;
//public GameObject container1;
void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(this.gameObject);
}
else
{
Destroy(gameObject);
}
SceneManager.sceneLoaded += Carrega;
}
#region Carrega
void Carrega(Scene cena, LoadSceneMode modo)
{
container1 = GameObject.FindWithTag("UI");
youLosePanel = container1.transform.GetChild(2).gameObject;
denovo = container1.transform.GetChild(2).GetChild(0).GetComponent<Button>();
//RestartLvl();
denovo.onClick.AddListener(Jogarnovamente);
RestartLvl();
}
#endregion
// Start is called before the first frame update
void Start()
{
gameOver = false;
RestartLvl();
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.R))
{
Jogarnovamente();
}
if (gameOver && !youLosePanel.activeSelf) {
FimdeJogo();
}
}
void Jogarnovamente()
{
SceneManager.LoadScene(1);
}
void RestartLvl()
{
gameOver = false;
StartCoroutine(tempo());
//youLosePanel.SetActive(false);
}
IEnumerator tempo()
{
yield return new WaitForSeconds(0.001f);
youLosePanel.SetActive(false);
}
void FimdeJogo()
{
youLosePanel.gameObject.SetActive(true);
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= Carrega;
}