[TUTORIAL] Texto Legenda Character Por Character Para Uso Básico
Página 1 de 1
[TUTORIAL] Texto Legenda Character Por Character Para Uso Básico
Edit:
boa tarde ,boa noite ,bom dia , fiz um scriptzinho só de bobeira ,como descrevia,talvez uma pequena legenda,como se escrevesse o inicio de um game em uma historia de quadrinhos que demorasse sei lá uns 5/10,20 segundos
depois d milhoes de erros encontrei o jeito;
o script pode ser um pouco complicado, mais para aqueles que entendem a lógica do "if", nao sera tao dificil de entender,
quem quiser testar é só criar uma Ui Text e uma imagem de fundo da legenda e crie e cole o script
Imagem Teste:
![[TUTORIAL] Texto Legenda Character Por Character Para Uso Básico JJ27t1J](https://i.imgur.com/JJ27t1J.png)
é tipo uma silaba a cada 2 segundos
Script:
Outra opçao eu fiz usando um botao para avançar para a proxima legenda, basta criar o botao com o nome button_next e o Text deste button para "next" se for outro altere o nome da da busca alem do texto e linkar a void a este botao, a primeira legenda aparece assim automaticamente assim q dar o play, o resto vai passando quando clicar o botao, assim q a legenda acabar o text do botao muda,e assim q vc pressionar, o botao é desativado.
obs: ficar pressionando o botao enquanto a legenda esta em andamento podera bugar o texto,e a legenda ira pausar,
o script é mais tipo pra uma abertura rapida,tanks for assistation se escreveshion no caneshion, hehe flw
boa tarde ,boa noite ,bom dia , fiz um scriptzinho só de bobeira ,como descrevia,talvez uma pequena legenda,como se escrevesse o inicio de um game em uma historia de quadrinhos que demorasse sei lá uns 5/10,20 segundos
depois d milhoes de erros encontrei o jeito;
o script pode ser um pouco complicado, mais para aqueles que entendem a lógica do "if", nao sera tao dificil de entender,
quem quiser testar é só criar uma Ui Text e uma imagem de fundo da legenda e crie e cole o script
Imagem Teste:
![[TUTORIAL] Texto Legenda Character Por Character Para Uso Básico JJ27t1J](https://i.imgur.com/JJ27t1J.png)
é tipo uma silaba a cada 2 segundos
Script:
- Código:
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
[System.Serializable]
public class ScrollLeg : MonoBehaviour
{
[SerializeField] string[] LegendaArray; //array de legendas
public int index = 0; //indice caracteres
public int indexlegenda = 0; //indice da legenda
public Text textoUI; //linkar text no inpector aqui
private float tempo= 0.2f; //tempo de cada silaba, etc
private string stringlegenda; //esta é a saida da legenda na ordem
bool startLegend; //ativar,desativar repeticao da legenda
//inicia-se quando dá o play
void Start()
{
//legenda de array foi declarada aqui pq o inspector não atualiza né q loko,aqui voce pode apagar e colocar suas legendas/palavras
LegendaArray = new string[]{ "ola, seja bem vindo ao tutorial de texto legenda,", "se voce esta lendo essas palavras isso chamamos de legenda scroll gostou?","vou advinhar voce pegou esse tutorial do forum schutlzgames acertei hehe..","obrigado por ler nosso tutorial volte sempre."};
startLegend = true;
StartCoroutine(ScrollLegend(LegendaArray,tempo));
}
private IEnumerator ScrollLegend(string[] leg,float time)
{
yield return new WaitForSeconds(time);
if (index < leg[indexlegenda].Length)
{
stringlegenda += leg[indexlegenda][index].ToString();
textoUI.text = stringlegenda;
index++;
}else
if (index > leg[indexlegenda].Length-1 && indexlegenda<LegendaArray.Length-1)
{
indexlegenda++;
index = 0;
stringlegenda = null;
}
if(index>=leg[indexlegenda].Length-1 && indexlegenda >= LegendaArray.Length - 1)
{
StopCoroutine(ScrollLegend(LegendaArray,time)); //parar o coroutine
indexlegenda = 0;// resetar indexlegenda
index = 0; //resetar o index de caracteres
stringlegenda = null; //zera a string
startLegend = false;
Debug.Log("fim!"); //ao ler todas as legendas printa um mensagem!
//alguma açao;
}
if (startLegend)
{
StartCoroutine(ScrollLegend(LegendaArray, time));
}
}
}
Outra opçao eu fiz usando um botao para avançar para a proxima legenda, basta criar o botao com o nome button_next e o Text deste button para "next" se for outro altere o nome da da busca alem do texto e linkar a void a este botao, a primeira legenda aparece assim automaticamente assim q dar o play, o resto vai passando quando clicar o botao, assim q a legenda acabar o text do botao muda,e assim q vc pressionar, o botao é desativado.
obs: ficar pressionando o botao enquanto a legenda esta em andamento podera bugar o texto,e a legenda ira pausar,
- Código:
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
[System.Serializable]
public class Teste : MonoBehaviour
{
[SerializeField] string[] LegendaArray; //array de legendas
public int index = 0; //indice caracteres
public int indexlegenda = 0; //indice da legenda
public Text textoUI; //linkar text no inpector aqui
private float tempo= 0.2f; //velocidade da legenda/character
string stringlegenda; //esta é a saida da legenda na ordem
public bool startLegend; //ativar,desativar repeticao da legenda
// Use this for initialization
void Start()
{
LegendaArray = new string[]{ "ola, seja bem vindo ao tutorial de texto legenda,", "se voce esta lendo essas palavras isso chamamos de legenda scroll gostou?","vou advinhar voce pegou esse tutorial do forum schutlzgames acertei hehe..","obrigado por ler nosso tutorial volte sempre."};
startLegend = true;
StartCoroutine(ScrollLegend(LegendaArray, tempo));
}
//esse void vc adiciona no OnClick no seu botao na cena ,clica no sinal de + e seleciona o objeto que contem este script e add a void
public void bton_legend()
{
//se o nome do botao for outro troque "button_next" por ele ,a mesma coisa com o text desse botao
if (GameObject.Find("button_next").transform.GetChild(0).GetComponent<Text>().text == "next" && !startLegend)
{
startLegend = true;
StartCoroutine(ScrollLegend(LegendaArray, tempo));
}
else
{
GameObject.Find("button_next").GetComponent<Button>().enabled = false;
//uma acao qualquer
Debug.Log("texto do button is Ok");
}
}
private IEnumerator ScrollLegend(string[] leg,float time)
{
yield return new WaitForSeconds(time);
if (index < leg[indexlegenda].Length)
{
stringlegenda += leg[indexlegenda][index].ToString();
textoUI.text = stringlegenda;
index++;
}else
if (index > leg[indexlegenda].Length-1 && indexlegenda<LegendaArray.Length-1)
{
indexlegenda++;
index = 0;
stringlegenda = null;
StopCoroutine(ScrollLegend(LegendaArray,time)); //parar o coroutine
startLegend = false;
}
if(index>=leg[indexlegenda].Length-1 && indexlegenda >= LegendaArray.Length - 1)
{
indexlegenda = 0;// resetar indexlegenda
index = 0; //resetar o index de caracteres
stringlegenda = null; //zera a string
startLegend = false; //bloqueia/parar o andamento da legenda
Debug.Log("fim!"); //print quando termina a ultima legendas/text
//alguma açao;
GameObject.Find("button_next").transform.GetChild(0).GetComponent<Text>().text = "Ok";
}
if (startLegend)
{
StartCoroutine(ScrollLegend(LegendaArray, time)); //enquanto o startlegend estiver true isso sera chamado
}
else
{
StopCoroutine(StartCoroutine(ScrollLegend(LegendaArray, time))); //para o coroutine
}
}
}
o script é mais tipo pra uma abertura rapida,tanks for assistation se escreveshion no caneshion, hehe flw
Última edição por FelipeSouza11 em Sab Out 06, 2018 10:07 am, editado 4 vez(es) (Razão : Atualizaçao de conteúdo)
FelipeSouza11- ProgramadorMaster
-
PONTOS : 2048
REPUTAÇÃO : 188
Idade : 29
Áreas de atuação : Programação C#,Html,css, javascript, Bolt vs
Respeito as regras :
Re: [TUTORIAL] Texto Legenda Character Por Character Para Uso Básico
valeu cara,tava procurando um sistema assim pra colocar no meu jogo .@FelipeSouza11 escreveu:Edit:
boa tarde ,boa noite ,bom dia , fiz um scriptzinho só de bobeira ,como descrevia,talvez uma pequena legenda,como se escrevesse o inicio de um game em uma historia de quadrinhos que demorasse sei lá uns 5/10,20 segundos
depois d milhoes de erros encontrei o jeito;
o script pode ser um pouco complicado, mais para aqueles que entendem a lógica do "if", nao sera tao dificil de entender,
quem quiser testar é só criar uma Ui Text e uma imagem de fundo da legenda e crie e cole o script
Imagem Teste:
é tipo uma silaba a cada 2 segundos
Script:
- Código:
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
[System.Serializable]
public class ScrollLeg : MonoBehaviour
{
[SerializeField] string[] LegendaArray; //array de legendas
public int index = 0; //indice caracteres
public int indexlegenda = 0; //indice da legenda
public Text textoUI; //linkar text no inpector aqui
private float tempo= 0.2f; //tempo de cada silaba, etc
private string stringlegenda; //esta é a saida da legenda na ordem
bool startLegend; //ativar,desativar repeticao da legenda
//inicia-se quando dá o play
void Start()
{
//legenda de array foi declarada aqui pq o inspector não atualiza né q loko,aqui voce pode apagar e colocar suas legendas/palavras
LegendaArray = new string[]{ "ola, seja bem vindo ao tutorial de texto legenda,", "se voce esta lendo essas palavras isso chamamos de legenda scroll gostou?","vou advinhar voce pegou esse tutorial do forum schutlzgames acertei hehe..","obrigado por ler nosso tutorial volte sempre."};
startLegend = true;
StartCoroutine(ScrollLegend(LegendaArray,tempo));
}
private IEnumerator ScrollLegend(string[] leg,float time)
{
yield return new WaitForSeconds(time);
if (index < leg[indexlegenda].Length)
{
stringlegenda += leg[indexlegenda][index].ToString();
textoUI.text = stringlegenda;
index++;
}else
if (index > leg[indexlegenda].Length-1 && indexlegenda<LegendaArray.Length-1)
{
indexlegenda++;
index = 0;
stringlegenda = null;
}
if(index>=leg[indexlegenda].Length-1 && indexlegenda >= LegendaArray.Length - 1)
{
StopCoroutine(ScrollLegend(LegendaArray,time)); //parar o coroutine
indexlegenda = 0;// resetar indexlegenda
index = 0; //resetar o index de caracteres
stringlegenda = null; //zera a string
startLegend = false;
Debug.Log("fim!"); //ao ler todas as legendas printa um mensagem!
//alguma açao;
}
if (startLegend)
{
StartCoroutine(ScrollLegend(LegendaArray, time));
}
}
}
Outra opçao eu fiz usando um botao para avançar para a proxima legenda, basta criar o botao com o nome button_next e o Text deste button para "next" se for outro altere o nome da da busca alem do texto e linkar a void a este botao, a primeira legenda aparece assim automaticamente assim q dar o play, o resto vai passando quando clicar o botao, assim q a legenda acabar o text do botao muda,e assim q vc pressionar, o botao é desativado.
obs: ficar pressionando o botao enquanto a legenda esta em andamento podera bugar o texto,e a legenda ira pausar,
- Código:
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
[System.Serializable]
public class Teste : MonoBehaviour
{
[SerializeField] string[] LegendaArray; //array de legendas
public int index = 0; //indice caracteres
public int indexlegenda = 0; //indice da legenda
public Text textoUI; //linkar text no inpector aqui
private float tempo= 0.2f; //velocidade da legenda/character
string stringlegenda; //esta é a saida da legenda na ordem
public bool startLegend; //ativar,desativar repeticao da legenda
// Use this for initialization
void Start()
{
LegendaArray = new string[]{ "ola, seja bem vindo ao tutorial de texto legenda,", "se voce esta lendo essas palavras isso chamamos de legenda scroll gostou?","vou advinhar voce pegou esse tutorial do forum schutlzgames acertei hehe..","obrigado por ler nosso tutorial volte sempre."};
startLegend = true;
StartCoroutine(ScrollLegend(LegendaArray, tempo));
}
//esse void vc adiciona no OnClick no seu botao na cena ,clica no sinal de + e seleciona o objeto que contem este script e add a void
public void bton_legend()
{
//se o nome do botao for outro troque "button_next" por ele ,a mesma coisa com o text desse botao
if (GameObject.Find("button_next").transform.GetChild(0).GetComponent<Text>().text == "next" && !startLegend)
{
startLegend = true;
StartCoroutine(ScrollLegend(LegendaArray, tempo));
}
else
{
GameObject.Find("button_next").GetComponent<Button>().enabled = false;
//uma acao qualquer
Debug.Log("texto do button is Ok");
}
}
private IEnumerator ScrollLegend(string[] leg,float time)
{
yield return new WaitForSeconds(time);
if (index < leg[indexlegenda].Length)
{
stringlegenda += leg[indexlegenda][index].ToString();
textoUI.text = stringlegenda;
index++;
}else
if (index > leg[indexlegenda].Length-1 && indexlegenda<LegendaArray.Length-1)
{
indexlegenda++;
index = 0;
stringlegenda = null;
StopCoroutine(ScrollLegend(LegendaArray,time)); //parar o coroutine
startLegend = false;
}
if(index>=leg[indexlegenda].Length-1 && indexlegenda >= LegendaArray.Length - 1)
{
indexlegenda = 0;// resetar indexlegenda
index = 0; //resetar o index de caracteres
stringlegenda = null; //zera a string
startLegend = false; //bloqueia/parar o andamento da legenda
Debug.Log("fim!"); //print quando termina a ultima legendas/text
//alguma açao;
GameObject.Find("button_next").transform.GetChild(0).GetComponent<Text>().text = "Ok";
}
if (startLegend)
{
StartCoroutine(ScrollLegend(LegendaArray, time)); //enquanto o startlegend estiver true isso sera chamado
}
else
{
StopCoroutine(StartCoroutine(ScrollLegend(LegendaArray, time))); //para o coroutine
}
}
}
o script é mais tipo pra uma abertura rapida,tanks for assistation se escreveshion no caneshion, hehe flw
vitorhugo- Membro
-
PONTOS : 1400
REPUTAÇÃO : 13
Idade : 19
Respeito as regras :
Página 1 de 1
Permissão deste fórum:
Você não pode responder aos tópicos neste fórum