I want to Instantiate an object (life) by hitting a block when the scene loads the first time, but when the scene resets or reloads (in case of after death), I dont’t want to instantiate the object again.
I tried to play with a bool, if the scene “reloads” = true, then don’t do that, but the scene reloads as a whole as it is supposed to be when it first runs. Or maybe I have the bool in the wrong place.
I would appreciate any help, and if the code is confusing I can explain.
This is the ResetSameScene method in the SceneLoader script:
public void ResetSameScene()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentSceneIndex);
isReload = true;
}
This is the method in the Block script where I want to instantiate the object:
private void TriggerSparklesVFX()
{
if (afterDeath.isReload == true & gameObject.name == "SpecialLifeBlock")
{
GameObject lifeOneUp = Instantiate(lifeUP, transform.position, transform.rotation);
}
...
...
...
}
and this is where the ResetSameScene gets triggered with the block collider:
IEnumerator myDelay()
{
yield return new WaitForSeconds(2.5f);
sceneloader.ResetSameScene();
FindObjectOfType<GameSession>().LoseLife();
}