Hey! i am currently working on a array with booleans which is supposed to stay when i switch levels, it has to keep its values but it loses the data.
public class SliderUpdateManager : MonoBehaviour
{
static bool[] boolarray;
public GameObject[] Objecten;
// Use this for initialization
void Start ()
{
//if(boolarray.Length == null)
boolarray = new bool [Objecten.Length];
}
void Awake()
{
DontDestroyOnLoad(this);
}
void SetBool(int i)
{
boolarray *= true;*
_ Objecten*.SetActive(false);_
_ }_
_ void RunValues()_
_ {_
_ for(int p = 0; p < boolarray.Length; p++)_
_ {_
_ if(boolarray[p] == true)_
_ {_
_ Objecten[p].SetActive(false);_
_ }_
_ }_
_ }_
_ // Update is called once per frame*_
* void Update ()*
* { *
* Debug.Log(boolarray[0]);*
* Debug.Log(boolarray[1]);*
* RunValues();*
* }*
}
besides that i also run another script to make sure it will stay, it works for another manager who do keeps it values!
public class KeepPlayer : MonoBehaviour {
* private static KeepPlayer instance;
_ // Use this for initialization*
* public static KeepPlayer instance*
* {*
* get*
* {*
* if(instance == null)
_ {*
* _instance = GameObject.FindObjectOfType();
DontDestroyOnLoad(instance.gameObject);
_ }*
* return instance;
_ }*
* }*
}
Any ideas? i can’t continue right now
Maybe when you switch the level - SliderUpdateManager::Start is being called, where array is initialized again?
Tomas helped me out!
void Start ()
{
if( !IsSet )
{
boolarray = new bool[Objecten.Length];
IsSet = true;
}
else
{
return;
}
}
this worked and kept my array values through switching!