void OnCollisionEnter(Collision collision)
 {
     if (collision.collider.tag == "Bola")
     {
         //Activar audio
         reproductorDeSonidos.Reproducir(hitAudio);
     }
 }
Esempio n. 2
0
    IEnumerator EscribirElTexto(string textoAEscribir)
    {
        //GENERAR LINEAS PARA EVITAR QUE EL TEXTO SALTE EN MITAD DE UNA PALABRA
        SetBestFit(true);
        texto.text = textoAEscribir;

        //Si no se hace esto el tamaño de la fuente generada con BestFit no coincide con el que debería tener no sé por qué ???
        texto.cachedTextGenerator.Invalidate();
        TextGenerationSettings tempSettings = texto.GetGenerationSettings(((RectTransform)texto.transform).rect.size);

        tempSettings.scaleFactor = 1;
        if (!texto.cachedTextGenerator.Populate(textoAEscribir, tempSettings))
        {
            Debug.LogError("Failed to generate fit size");
        }
        //--------

        string[] lineas = new string[texto.cachedTextGenerator.lineCount];
        for (int i = 0; i < lineas.Length; i++)
        {
            int indice = texto.cachedTextGenerator.lines[i].startCharIdx;
            if (i < lineas.Length - 1)
            {
                int indiceFinal = texto.cachedTextGenerator.lines[i + 1].startCharIdx;
                lineas[i] = textoAEscribir.Substring(indice, indiceFinal - indice);
            }
            else
            {
                lineas[i] = textoAEscribir.Substring(indice);
            }
            lineas[i] = lineas[i].Trim();
        }

        SetBestFit(false); //aquí se asigna el tamaño de la fuente generada al tamaño predeterminado de la fuente

        //ESCRIBIR EL TEXTO

        texto.text = "";
        bool sonar = false;

        for (int linea = 0; linea < lineas.Length; linea++)
        {
            for (int i = 0; i < lineas[linea].Length; i++)
            {
                string caracter = lineas[linea].Substring(i, 1);

                if (caracter == "$")
                {
                    yield return(new WaitUntil(() => Input.GetKeyDown(ConfiguracionTeclas.avanzarConversacion)));
                }
                else
                {
                    texto.text += caracter;

                    sonar = !sonar;
                    if (sonar)
                    {
                        reproductorDeSonidos.Reproducir(sonidoTypewriter);
                    }

                    yield return(new WaitForSeconds(velocidadTexto));
                }
            }
            texto.text += "\n";
        }

        sePuedeAvanzarElTexto = true;
    }