I'm making something for a dialogue system that reads "cues" from a textfile to identify which emotion to show in the character's portrait during a conversation. Basically if the current line says "2", it means change the portrait to where the character is smiling. "1" for neutral, etc. Unfortunately the part that compares the emotion variable, and the string from the text file doesn't return true.
I already checked using debug.log if the string from the text file is showing the right number, and it does. I tried comparing them using "==" sign and ".equals();" but neither seems to work.
public TextAsset textFileP;
public string[] textLineP;
public GameObject character;
public Animator anim;
public string smile = "2";
void Start()
{
anim = GetComponent<Animator>();
if (textFileP != null)
{
textLineP = (textFileP.text.Split('\n'));
character.SetActive(true);
}
}
void Update()
{
if (DialogueParser.nextLine < DialogueParser.textLine.Length - 1)
{
//change portrait
if (Input.GetKeyDown(KeyCode.Mouse0))
{
string cue = textLineP[DialogueParser.nextLine];
// Debug.Log(cue);
if (cue.Equals(smile))
{
anim.SetInteger("2", 2);
}
}
\n
when they might also include a\r
. After splitting, that leaves you with strings with an invisible character at one end, enough to make them compare as not equal. You may want to use string methods likeTrim()
andToLowerInvariant()
to normalize your texts for comparison. \$\endgroup\$