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

292
Vistas
c# unity pause a for loop untill bool returns true

i have a for loop that loops through a class array instantiating a new player class and passing in a string(name).

public void createPlayers( int pInput)
{
    //holds name
    string temporaryString="defualt";
    players = new Player[pInput];
   

    for (int i = 0; i < pInput; ++i)
    {
       
        //PlayerTypesNameFunction()// this gets and returns a string to Temporary String
        //wait till function returns with true meaning player(i) has entered name

        players[i] = new Player(100,temporaryString);
        Debug.Log(players[i].m_sName);
    } 
        
    CurrentState = GameState.m_eQueueWeather;
    CallGameCurrentState();


}

I want it to call a function which gets the player to type a name and only continue for loop when that function finishes. changes a bool to true(bool gotInfo), the loop then continues to take the string which is returned and stored in temporaryString (string instatiated above) and assigns it to the new player in this line players[i] = new Player(100,temporaryString);.

Am I heading in the right direction or should I approach this problem differently? Thank you in advance

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

0

I would not suggest the infinite loop here. I would go for the yield return subrutine method that's explained here

Create the subrutine

 IEnumerator WaitForKeyDown(KeyCode keyCode)
 {
     while (!Input.GetKeyDown(keyCode))
         yield return null;
 }

Wait wherever you want

 yield return StartCoroutine(WaitForKeyDown(KeyCode.Return));

This will resume when the user presses enter. You can then check the input value and re-ask.

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