Есть класс:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainGame : MonoBehaviour
{
internal int gameMod = -1;
private void OnGUI()
{
Debug.Log("D02 gameMod OnGUI = " + gameMod);
float centrScreenX = Screen.width / 2;
float centrScreenY = Screen.height / 2;
switch (gameMod)
{
case 0:
{
Rect LocationButton = new Rect(new Vector2(centrScreenX - 150, centrScreenY - 50), new Vector2(300, 200));
GUI.Box(LocationButton, "");
}
break;
}
}
Меняю переменную gameMod вызовом метода из другого класса, вот этот метод:
private void InitializeDefaultScreen()
{
MainGame gameModStart = new MainGame();
gameModStart.gameMod = 0;
Debug.Log("D02 D03 gameMod = " + gameModStart.gameMod);
ImageTracker tracker = _uiScreens[(int)InteractionManagerState.SeeBattle].GetComponent<ImageTracker>();
if (!tracker)
{
throw new MissingComponentException(tracker.GetType().Name + " component not found!");
}
ShowPlanes(false);
tracker.Initialize();
}
Но в классе MainGame значение переменной не меняется. Логи:
2023.01.24 16:42:40.315 16412 18550 Info Unity D02 gameMod OnGUI = -1
2023.01.24 16:42:40.316 16412 18550 Info Unity D02 gameMod OnGUI = -1
2023.01.24 16:42:40.316 16412 18550 Info Unity D02 gameMod OnGUI = -1
2023.01.24 16:42:40.349 16412 18550 Info Unity D02 D03 gameMod = 0
2023.01.24 16:42:40.402 16412 18550 Info Unity D02 gameMod OnGUI = -1
2023.01.24 16:42:40.402 16412 18550 Info Unity D02 gameMod OnGUI = -1
2023.01.24 16:42:40.414 16412 18550 Info Unity D02 gameMod OnGUI = -1