Hi,
I’m using Application.LoadLevel(level1) to load level.
I’d like the scene gameobjects to be completely reset but it just doesn’t happen.
Score counters work normally however.
so, when my player dies, death screen (canvas, not a separate scene) appears.
There are two buttons. Main Menu and restart.
If i press restart, the scene loads but all gameobjects which got activated during gameplay are still active even though they shouldnt be. Same thing happens if on death screen main menu is pressed, main menu loads, then i press new game and it loads the scene with what was there during gameplay.
Score counter (starts from 0 and it ads points per second) works normally however.
I never use DontDestroyOnLoad() for anything as i don’t need it.
I’ve tried using application.loadlevel(LoadedLevel) for restart but that restarts the scene without starting any script or effect that should be there from the start. It just loads gameobjects that should be there.
Please help,
thank you.
edit:
well. turn’s out the problem is my spawning script. I should’ve posted it. : /
i’m getting current score from player prefs from my score manager but it’s like for some reason spawn script sometimes starts from last current score for a milisecond i think. : / i dont save player prefs for this score as it needs to clear on every playthrough.
My current solution is to just place spawn parts of code into score manager. From there it works with no problems. I would rather have them separately.
SpawnScript
…` void Start()
{
scoreCounter = PlayerPrefs.GetFloat(scoreKeyyerer, 0);
}
void FixedUpdate()
{
scoreCounter = PlayerPrefs.GetFloat(scoreKeyyerer, 0);
PlayerPrefs.GetFloat(scoreKeyyerer, scoreCounter);
enemies = GameObject.FindGameObjectsWithTag("Enemy");
if (scoreCounter < 400)
{
InvokeRepeating(“spawnEnemy”, 2, 3f);
}
if(scoreCounter > 500) // leaving 100points for first enemy to get completely cleared
{
cann.gameObject.SetActive(true);
}
spawn script...
void Start()
{
scoreCounter = PlayerPrefs.GetFloat(scoreKeyyerer, 0);
updteScoreManager = GetComponent<MyScoreManager>();
}
void FixedUpdate()
{
scoreCounter = PlayerPrefs.GetFloat(scoreKeyyerer, 0);
PlayerPrefs.GetFloat(scoreKeyyerer, scoreCounter);
enemies = GameObject.FindGameObjectsWithTag("Enemy");`
if (scoreCounter < 400)
{
InvokeRepeating("spawnEnemy", 2, 3f);
}
if(scoreCounter > 500) // leaving 100points for first enemy to get completely cleared
{
cann.gameObject.SetActive(true);
}
if(scoreCounter<800)
{
cann.gameObject.SetActive(false);
}
if (scoreCounter > 800 && scoreCounter < 1200)
{
InvokeRepeating("spawnEnemy3", 2, 3f);
}
...
scoremanager
...
void Update()
{
if (scoreIncreasing)
{
scoreCount += pointsPerSecond * Time.deltaTime;
PlayerPrefs.SetFloat(scoreKeyyerer, scoreCount);
}
...
}
...