- Home /
Full scene restart
Hey guys, so I got this small game I am working on and I am using PoolManager, I am not getting any errors but when I use my restart button using this code...
using UnityEngine;
using System.Collections;
public class FullRestart : MonoBehaviour
{
void OnClick()
{
Application.LoadLevel ("Level_1");
}
}
I am not getting it to again start the enemies to spawn, they don't spawn ever again and I am not getting any error. The code for my spawning enemies is this and its set to false until I press a button in game...
using UnityEngine;
using System.Collections;
using PathologicalGames;
public class EnemySpawning : MonoBehaviour
{
public float spawnTime = 3.0f;
float timeLeft = 0.0f;
public static bool isSpawning = false;
public Transform español = null;
void Update ()
{
if (isSpawning != false)
{
timeLeft -= Time.deltaTime;
if (timeLeft <= 0.0f)
{
Transform t = PoolManager.Pools["Enemy"].Spawn(español, transform.position, Quaternion.identity);
timeLeft = spawnTime;
}
}
}
}
So if you guys ever faced a problem like this please I would love to get some help, thank you all in advance!
Do you have any objects marked as "DontDestroyOnLoad"?
None... I am not using the DontDestroyOnLoad method anywhere!
static variables won't be re-initialized on scene change. Where do you set isSpawning? $$anonymous$$aybe check for any other static variables that impact isSpawning.
Yeah I restart all the static variables on the void Start() but still the spawning is not occurring from the pool, and I see the pool being created and the units instantiated!
Can you show how you are re-initializing the static variables?
Answer by iriegusto · Mar 03, 2021 at 02:00 AM
I had the same problem, and this simple code insert fixed it for me:
public void Awake()
{
Time.timeScale = 1;
}