protected override void OnUpdate()
    {
        //Componente que contiene los tiempos de spawn de cada elemento
        TiempoSpawnComponent componente = m_TiempoSpawn.GetComponentDataArray <TiempoSpawnComponent>()[0];

        /****** SPAWN OBSTACULOS *******/

        //Comprobar si se ha agotado el tiempo de espera del spawner de obstaculos
        float tiempoObstaculos = componente.segundosObstaculos;

        tiempoObstaculos = Mathf.Max(0.0f, componente.segundosObstaculos - Time.deltaTime);
        bool spawnObstaculo = tiempoObstaculos <= 0.0f;

        //Resetear el tiempo de espera si se ha agotado
        if (spawnObstaculo)
        {
            //Calcular cuanto hay que reducir tiempo de spawn en funcion del tiempo de juego
            // (reducir el tiempo de spawn al aumentar la velocidad de movimiento)
            TemporizadorComponent temporizadorComponent = m_Temporizador.GetComponentDataArray <TemporizadorComponent>()[0];
            float tiempoTotal = Time.time - temporizadorComponent.startTime; //tiempo que ha pasado desde el inicio del juego
            int   t           = (int)(tiempoTotal / 20);                     //cada 20s, la velocidad aumenta y el tiempo de spawn disminuye

            tiempoObstaculos = Mathf.Max(0.5f, 1.2f - 0.15f * t);            //reducir 0.15s cada 20s, hasta un minimo de 0.5s
        }

        //Array de obstaculos que estan inactivos
        EntityArray obstaculosInactivos = m_Obstaculos.GetEntityArray();

        //Spawnear obstaculo si el tiempo de espera ha llegado a 0 y si quedan obstaculos por activar
        // (se supone que siempre van a quedar obstaculos por activar, puesto que da tiempo a que alguno se desactive)
        if (spawnObstaculo && obstaculosInactivos.Length > 0)
        {
            //Escoger tipo de obstaculo aleatoriamente
            int idObstaculo = UnityEngine.Random.Range(0, 3);
            //Escoger posicion aleatoriamente
            float posicionX;
            if (idObstaculo == 2)
            {
                //Los palillos solo pueden aparecer en los extremos
                posicionX = posiciones[UnityEngine.Random.Range(0, 2)];
            }
            else
            {
                posicionX = posiciones[UnityEngine.Random.Range(0, 3)];
            }

            JobHandle jobActivar = new ActivarObstaculo()
            {
                obstaculosInactivos = obstaculosInactivos,
                Commands            = _collisionBarrier.CreateCommandBuffer(),
                randomId            = UnityEngine.Random.Range(0, obstaculosInactivos.Length),
                posicionX           = posicionX,
                idObstaculo         = idObstaculo
            }.Schedule();
            jobActivar.Complete();
        }


        /************ SPAWN PREMIOS *******/

        //Comprobar si se ha agotado el tiempo de espera del spawner de premios
        float tiempoPremios = componente.segundosPremios;

        tiempoPremios = Mathf.Max(0.0f, componente.segundosPremios - Time.deltaTime);
        bool spawnPremios = tiempoPremios <= 0.0f;

        if (spawnPremios)
        {
            //Resetear
            tiempoPremios = 7.0f; //7 segundos entre premios (no disminuye con la velocidad)
        }

        //Array de premios que estan inactivos
        EntityArray premiosInactivos = m_Premios.GetEntityArray();

        //Spawnear premio si el tiempo de espera ha llegado a 0 y si quedan premios por activar
        if (spawnPremios && premiosInactivos.Length > 0)
        {
            //Escoger posicion aleatoriamente
            float posicionX = posiciones[UnityEngine.Random.Range(0, 3)];

            JobHandle jobActivar = new ActivarPremio()
            {
                premiosInactivos = premiosInactivos,
                Commands         = _collisionBarrier.CreateCommandBuffer(),
                randomId         = UnityEngine.Random.Range(0, premiosInactivos.Length),
                posicionX        = posicionX
            }.Schedule();
            jobActivar.Complete();
        }

        //Actualizar el tiempo que queda en el componente
        Entity ent = m_TiempoSpawn.GetEntityArray()[0];

        EntityManager.SetComponentData <TiempoSpawnComponent>(ent, new TiempoSpawnComponent {
            segundosObstaculos = tiempoObstaculos,
            segundosPremios    = tiempoPremios
        });
    }
        protected override void OnUpdate()
        {
            //Componente que contiene los tiempos de spawn de cada elemento
            TiempoSpawnCMP_NV tiempoSpawnComponent = m_TiempoSpawn.GetComponentDataArray <TiempoSpawnCMP_NV>()[0];

            /****** SPAWN ENEMIGOS *******/

            //Comprobar si se ha agotado el tiempo de espera del spawner de enemigos
            float tiempoNaves = tiempoSpawnComponent.segundosNaves;

            tiempoNaves = Mathf.Max(0.0f, tiempoSpawnComponent.segundosNaves - Time.deltaTime);
            bool spawnNave = tiempoNaves <= 0.0f;

            //Resetear el tiempo de espera si se ha agotado
            if (spawnNave)
            {
                //Calcular cuanto hay que reducir tiempo de spawn en funcion del tiempo de juego
                temporizadorComponent = m_Temporizador.GetComponentDataArray <TemporizadorCMP_NV>()[0];
                float tiempoTotal = Time.time - temporizadorComponent.startTime; //tiempo que ha pasado desde el inicio del juego
                int   t           = (int)(tiempoTotal / 20);                     //cada 20s, el tiempo de spawn se reduce
                tiempoNaves = Mathf.Max(0.5f, 3.0f - 0.4f * t);                  //reducir 0.4s cada 20s, hasta un minimo de 0.5s
            }

            //Array de naves que estan inactivas
            //EntityArray navesInactivas = m_Enemigos.GetEntityArray();

            //Spawnear nave si el tiempo de espera ha llegado a 0 y si quedan naves por activar
            if (spawnNave)
            {
                //Generar posiciones aleatorias hasta encontrar una que no se solape con otrar naves activas
                bool valida;
                do
                {
                    posicionEnemigoX   = UnityEngine.Random.Range(-3f, 3f);
                    posicionesEnemigoY = new Vector2(UnityEngine.Random.Range(5.5f, 8f), UnityEngine.Random.Range(-3.3f, -6.8f));
                    int a = (int)UnityEngine.Random.Range(0, 2);
                    posicionEnemigoY = posicionesEnemigoY[a];

                    valida = CompararPosiciones(posicionEnemigoX, posicionEnemigoY);
                } while (valida == false); ///Sale del bucle al encontrar una posicion valida


                //Elegir nave hija target aleatoriamente y obtener su posicion
                int    idTarget       = (int)UnityEngine.Random.Range(0, m_NavesHijas.CalculateLength());
                float3 posicionTarget = m_NavesHijas.GetComponentDataArray <Position>()[idTarget].Value;

                CrearEnemigo(posicionEnemigoX, posicionEnemigoY, posicionTarget);
            }

            /***** SPAWN PREMIOS *****/
            //Comprobar si se ha agotado el tiempo de espera del spawner de premios
            float tiempoPremios = tiempoSpawnComponent.segundosPremios;

            tiempoPremios = Mathf.Max(0.0f, tiempoSpawnComponent.segundosPremios - Time.deltaTime);
            bool spawnPremios = tiempoPremios <= 0.0f;

            if (spawnPremios)
            {
                //Resetear
                tiempoPremios = UnityEngine.Random.Range(15f, 30f);
            }

            //Array de premios que estan inactivos
            EntityArray premiosInactivos = m_Premios.GetEntityArray();

            //Spawnear premio si el tiempo de espera ha llegado a 0 y si quedan premios por activar
            if (spawnPremios && premiosInactivos.Length > 0)
            {
                //Escoger posicion aleatoriamente
                posicionPremioX   = UnityEngine.Random.Range(-2.4f, 2.4f);
                posicionesPremioY = new Vector2(UnityEngine.Random.Range(2.52f, 4.8f), UnityEngine.Random.Range(-1.8f, -3.28f));
                int a = (int)UnityEngine.Random.Range(0, 2);
                posicionPremioY = posicionesPremioY[a];

                JobHandle jobPremio = new ActivarPremio()
                {
                    premiosInactivos = premiosInactivos,
                    Commands         = _collisionBarrier.CreateCommandBuffer(),
                    randomId         = UnityEngine.Random.Range(0, premiosInactivos.Length),
                    posicionX        = posicionPremioX,
                    posicionY        = posicionPremioY
                }.Schedule();
                jobPremio.Complete(); //Esperar a que termine el trabajo
            }

            //Actualizar el tiempo que queda en el componente
            Entity ent = m_TiempoSpawn.GetEntityArray()[0];

            EntityManager.SetComponentData <TiempoSpawnCMP_NV>(ent, new TiempoSpawnCMP_NV {
                segundosNaves   = tiempoNaves,
                segundosPremios = tiempoPremios
            });
        }