What I need to do is to translate every line (element) from Dialogue script in english to portuguese, but I don’t have any idea I can do to make this work, I appreciate any help.
Here is the code from script Dialogue if necessary:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Dialogue : MonoBehaviour
{
public TextMeshProUGUI textComponent;
public string[] lines;
public float textSpeed;
private int index;
// Start is called before the first frame update
void Start()
{
textComponent.text = string.Empty;
StartDialogue();
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Action"))
{
if (textComponent.text == lines[index])
{
NextLine();
}
else
{
StopAllCoroutines();
textComponent.text = lines[index];
}
}
}
void StartDialogue()
{
index = 0;
StartCoroutine(TypeLine());
}
IEnumerator TypeLine()
{
//Type each character 1 by 1
foreach (char c in lines[index].ToCharArray())
{
textComponent.text += c;
yield return new WaitForSeconds(textSpeed);
}
}
void NextLine()
{
if (index < lines.Length - 1)
{
index++;
textComponent.text = string.Empty;
StartCoroutine(TypeLine());
}
else
{
gameObject.SetActive(false);
index = 0;
}
}
}
You could make each line a separate entry in the table instead of using a single entry.
Or you could get the value and then split it by new line characters.
e.g var lines = translatedString.Split(“\n”);
Is it possible to change the key bindings? You may want to make the values dynamic. Something like
Oh yes! I forgot to mention if using key bindings are acceptable, thanks for that! This will work with gamepad buttons as well?
Sorry for being a noob but I still don’t get it how to split into lines, could you give an example like a picture? or this: e.g var lines = translatedString.Split(“\n”); where I can put this and then what I do, thank you for replying.
You will need to implement it. We don’t have a direct binding to Input at the moment. So you can get the Actions and then pass them into the GetStringAsync as arguments.
I’m sorry Karl, I still don’t get it the code you gave me, if you don’t mind could you show me where I can put this on the code? I tried to put and used:
using UnityEngine.Localization.Settings; but later GetStringAsync shows a error that I don’t get it.
Show me and explain step by step how to do it and preferably with images for better understanding. I’m not lazy, I just want to learn and dealing with this in programming still is is very difficult for me.
No problem Karl! that solved my problem, by the way in “/n” I changed to ‘/n’ and the worked!
Just one thing, I will use this code for every dialog, then I will need to change the “lvl_1” and “Dialog_01”. I created a public string for doing this but I failed, could you help me one last time with this?