Tengo un problema, tengo tres escenas en mi juego, tienda, menú principal y juego. En el juego tengo un script que genera enemigos cada segundo. Entonces, mi problema es que si espero 20 segundos en el menú principal o en la tienda y voy al juego, generará 20 enemigos a la vez (el script está en el objeto vacío del juego), probé muchas soluciones. Ese es mi último script enemigo de generación:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class SpawnScript : MonoBehaviour { public Transform[] spawnPoints; public GameObject[] enemyPrefabs; public float nextActionTime; public float period; private bool startScript = false; void Start() { Scene currentScene = SceneManager.GetActiveScene(); string sceneName = currentScene.name; if (sceneName == "Game") { nextActionTime = 0.0f; period = 1f; startScript = true; } } void Update() { if (startScript != false) { if (Player.isDead != true) { if (Time.time > nextActionTime) { nextActionTime += period; int spawnArrayKey = Random.Range(0, 4); int enemyId = Random.Range(0, 3); Instantiate(enemyPrefabs[enemyId], spawnPoints[spawnArrayKey].position, spawnPoints[spawnArrayKey].rotation); } } } } } También traté de cambiar void Start() para void Awake() , todavía no funciona, aquí está el script del menú principal que es muy simple
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class Buttons : MonoBehaviour { public void PlayGame() { SceneManager.LoadScene("Game"); } public void GoToShop() { SceneManager.LoadScene("Shop"); } }Encontré la respuesta, tenía Time.time en mi script, lo configuré en Time.timeSinceLevelLoad y ahora funciona