Hi, I want to change the value on isUsingML and isUsingElement. Well on first load, it can change like usual when the button is clicked, but after change to another scene and come back again to the first scene, the value cannot be change after the button clicked.
Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameMode : MonoBehaviour
{
public static bool isUsingMLAgent;
public static bool isUsingElement;
private static GameMode instance;
public void Awake()
{
isUsingElement = true;
isUsingMLAgent = true;
DontDestroyOnLoad(this);
if (instance == null)
{
instance = this;
}
else
{
Destroy(gameObject);
}
}
public void usingML(bool isUsingML)
{
if (instance == null)
{
instance = this;
}
if (isUsingML)
{
isUsingMLAgent = true;
}
else
{
isUsingMLAgent = false;
}
}
public void usingElement(bool isElement)
{
if (instance == null)
{
instance = this;
}
if (isElement)
{
isUsingElement = true;
}
else
{
isUsingElement = false;
}
}
}
Thank you
What do you mean by "the value cannot be changed"? 1. You shouldn't make the isUsingMLAgent and isUsingElement bools static. The bools can be referenced via GameMode.instance.isUsingMLAgent if you need to access them in another class. 2. You also don't need to assign (instance = this ) in any functions except Awake.
– ArachnidAnimalWell i've tried about your comment before i wrote this code, and it's still not working, and after that, i've tried using static (tbh, i don't know what does it do) and it still doesn't work. And what I try to achieve was using the method usingML and usingElement on my button (so I accessed it on the same class), but it still not working
– Mikahide