First time posting here not sure if proper format sorry. I am trying to use a button to change the gamemode in my game back to the in game mode with is game mode = 1 but it only works if I start the game in the menu that has the replay button. when the button is pressed it changes the game mode to 1 and the ingame = false so the if statement for ingame should run but it doesn’t. It seems like the if statement is only allowed to run once does anyone have an idea as to why this is? Thanks
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameMaster : MonoBehaviour
{
public int gamemode;
public GameObject cammenu;
public GameObject camgame;
public GameObject camdeath;
public GameObject menu;
public GameObject game;
public GameObject death;
public Texture2D crosshair;
public Texture2D menumouse;
bool ingame = false;
bool inmenu = false;
bool indeath = false;
public Camera mainCam;
public static GameMaster gm;
public int gamescore;
public HealthBar healthbar;
private void Awake()
{
if (gm == null)
{
gm = this;
}
gamemode = 0;
if (mainCam == null)
{
mainCam = Camera.main;
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//Main Menu
if (gamemode == 0 && inmenu == false)
{
inmenu = true;
indeath = false;
ingame = false;
menu.SetActive(true);
death.SetActive(false);
game.SetActive(false);
camdeath.SetActive(false);
camgame.SetActive(false);
cammenu.SetActive(true);
Cursor.SetCursor(crosshair, new Vector2(64, 64), CursorMode.Auto);
}
//In Game
if (gamemode == 1 && ingame == false)
{
print("Ingame started");
ingame = true;
indeath = false;
inmenu = false;
menu.SetActive(false);
death.SetActive(false);
game.SetActive(true);
cammenu.SetActive(false);
camdeath.SetActive(false);
camgame.SetActive(true);
Cursor.SetCursor(crosshair,new Vector2(64, 64),CursorMode.Auto);
//set score to 0 and set health to max
ScoreUI.sui.setscore(0);
healthbar.sethealth(10);
}
//death screen
if (gamemode == 2 && indeath == false)
{
indeath = true;
ingame = false;
inmenu = false;
menu.SetActive(false);
death.SetActive(true);
game.SetActive(false);
camgame.SetActive(false);
cammenu.SetActive(false);
camdeath.SetActive(true);
Cursor.SetCursor(crosshair, new Vector2(64, 64), CursorMode.Auto);
DestroyAll("Enemy");
}
}
void DestroyAll(string tag)
{
GameObject[] enemies = GameObject.FindGameObjectsWithTag(tag);
for (int i = 0; i < enemies.Length; i++)
{
Destroy(enemies[i]);
}
}
public void changegamemode(int mode)
{
gamemode = mode;
}
public void Addscore(int score)
{
gamescore += score;
Debug.Log("score is: " + gamescore);
ScoreUI.sui.setscore(gamescore);
}
public void Replay()
{
print("this button works");
gamemode = 1;
print(gamemode);
print(ingame);
}
}