Hello all! I have an issue right now. Currently I have a function which will check to see if an array in a string is equal to one that I input into the function. However I have found out that something which stops the script from working properly is that a normal string seemingly cannot be equal to a string from a string array even if they are equal on sight (I have tested this via debug.log).
My question is how I can compare these two or convert one of them to allow proper comparison.
Here is my main script:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class dialogue : MonoBehaviour
{
public TextAsset dialogueFile; //The .txt file the script draws its dialogue lines from
public string[] lineTitle; //the array that holds the titles of the dialogue line
public string[] line;//the array that holds the actual contents of the dialogue line
public GameObject sub;//The on-screen text object used to display the dialogue line
private float timeHolder; // holds the countdown duration
private bool timeOut = true; //Determines if time has run out for the subtitle's appearance yet. If this is false, the subtitle line will be deactivated
void Start ()
{
sub.SetActive (false);
}
// Update is called once per frame
void Update ()
{
//Starts Counting down
if (timeOut == false) {
timeHolder -= Time.deltaTime;
if (timeHolder < 0) {
sub.SetActive (false);
timeOut = true;
}
}
}
public void displayLine (string lineName, float duration)
{
string[] lines = dialogueFile.text.Split ('
'); //Creates a string array from the .txt file
timeHolder = duration;
for (int g = 0; g<3; g++) {
lineTitle [g] = lines [g * 3]; //puts line title in appropriate string array slot
line [g] = lines [1+ (g * 3)]; //puts actual line in appropriate string array slot
if (lineName==lineTitle [g]) { //The MAIN part which does not work. Should be comparing the line title to the line I input in a function. Displays the subtitle if this is true
sub.SetActive (true);
Debug.Log(lineTitle [g]);
sub.GetComponent<UnityEngine.UI.Text> ().text = line [g];
timeOut = false;
}
}
}
}
Here is what an example of the main “displayLine” function from the previous script being used:
displayLine("testLine1",3);
Here is what the .txt file that I draw the dialogue lines from looks like (Placeholder lines):
testLine1
I am going to try and decide what to do
//////////////////////////////
testLine2
Maybe this will work just fine?
//////////////////////////////
testLine3
How about we try being certain about it?
//////////////////////////////