Question by
Castermaluney · May 26, 2016 at 01:46 PM ·
sceneloadscene-loadingreloadscene load
After reloading the scene twice one script doesn't work.
I have this script:
private string powerUp = "no";
void OnTriggerEnter(Collider newCollider)
{
switch (newCollider.tag)
{
case "Fire":
powerUp = "fire";
Destroy(newCollider.gameObject);
break;
case "Wind":
powerUp = "wind";
Destroy(newCollider.gameObject);
break;
case "Earth":
powerUp = "earth";
Destroy(newCollider.gameObject);
break;
case "Water":
powerUp = "water";
Destroy(newCollider.gameObject);
break;
case "Lightning":
powerUp = "lightning";
Destroy(newCollider.gameObject);
break;
default:
break;
}
}
This code works, for the first two times. What happens is when i press play in the editor it works, then when i hit the replay button that run this code:
public string levelToLoad;
public void LoadLevel()
{
SceneManager.LoadScene(levelToLoad);
}
it still works. If I run the reload code a second time it stops working(so I'm assuming that the problem must happen whith the LoadScene function).
I've checke all i could, and for some reason i can't understand it just doesn't do"powerUp = "whatever". I've put logs all around it, and they always appear in the console. It also destroys the trigger as instructed. It just doesn't change the string powrUp. And only after the second LoadScene.
Anybody got any Idea what is happening?
(I'm using version 5.3.3f1)
Comment