It really is hard to guess what isn’t being reset with no code. In general, any static variables, or objects marked as DontDestroyOnLoad() will stick around, and will not reset.
You’ll have to use the OnLevelWasLoaded callback to reset those manually.
Except for where you specifically tell it not to, it destroys all scripts and loads new instances of them. Past that, I can only agree with what the others have already said, and suggest getting a better understanding of how static variables work (and where they should/shouldn’t be used) if you are indeed using them.
This script works at the start, but once I reload my level it doesnt work again.
voidStart()
{
if(amountCC<=0)
{
Debug.Log("Add # of TileColor in AmountCC");
enabled=false;
}
}
void OnTriggerEnter( Collider other )
{
GameObject[] tiles = GameObject.FindGameObjectsWithTag("TileColor");
int count = 0;
foreach( GameObject t in tiles )
{
ChangeColor cc = t.GetComponent<ChangeColor>();
if ( !cc.isBlack )
break;
else
count++; // add one to our count if it is black
}
if ( count == amountCC )
{
Invoke ("WinFreeze", delayLoad);
print("=============THE END IS WORKING=============");
}
}
This is the Reload Level Script, which works to load normal scenes back and forth like menu to options to credits etc.
using UnityEngine;
using System.Collections;
using MadLevelManager;
public class endCheck : MonoBehaviour
{
public float delayLoad = 0.5f;
public int amountCC;
and at the bottom:
void WinFreeze() {
Time.timeScale = 0.01f;
// gameObject.GetComponent<PlayerOneController> ().enabled = false;
print (" ============= THE END IS WORKING ============= ");
}
}
Thought these to parts are pretty irrelevant (even when Time.timeScale = 1 it doesnt work)
Yes, they are irrelevant, but how were we meant to know that without knowing what’s in them?
At any rate, you have public variables in there. Are you certain that they aren’t being accessed or modified from elsewhere? (You can mark them as [SerializeField] and private to make them accessible via the Inspector but also ensuring that other code can’t directly mess with it.)
Maybe you are expecting gameobjects to always get value of the prefab when game starts? It’s easy to make a mistake that you change some value for a test in gameobject, to override prefab. Then you change prefab’s to some other value, but your scene’s object still has the overriden value set to it. If that’s the case the value will show up in inspector as bolded. You can fix those by right clicking the name and select “revert to prefab value”.
I know that this post is years old, but I was wondering how would you suggest that I hadle game states, because Im doing exactly that (using static fields ) and Im having the same issue (I need to access these fields from other scripts by the way…)