Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

287
Vistas
Unity Bug con unity time y scene manager

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"); } }

También aquí está mi administrador de compilación ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Encontré la respuesta, tenía Time.time en mi script, lo configuré en Time.timeSinceLevelLoad y ahora funciona

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda