error de Unity con unity administrador de tiempo y escena
– UnityAssets3Free
hola , soy Juan y para hoy os traigo
nueva pregunta curiosa
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 al mismo tiempo (el script está en un objeto de juego vacío), probé muchas soluciones. Este es mi último script enemigo engendrado:
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()
por 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
1 respuesta 1
Encontré la respuesta, tenía Time.time
en mi script lo configuré para Time.timeSinceLevelLoad
Y ahora funciona
nota: si aun no se resuelve tu pregunta por favor dejar un comentario y pronto lo podremos de nuevo , muchas gracias
por hoy,hasta la proxima