Textbox text not changing.
Hey guys I want to change a quest name when the player has talked to a NPC. I tried doing it but everything works except the changing text part. Here is the script-
using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.SceneManagement; using UnityStandardAssets.Characters.FirstPerson;
public class WillEndTalk : MonoBehaviour {
public GameObject readyToGoCheck;
public GameObject warp;
public bool textBoxOnCheck = false;
public GameObject messageBox;
public GameObject textBox;
public string messageText;
public GameObject questText;
public string questName;
public Text questNameText;
public bool talkProgress = false;
public Text ringCountText;
public Color endDialogueBoxColor;
public Image dialoguePanel;
void OnMouseDown () {
if (!enabled) return;
if ((textBoxOnCheck == false) && (ringCountText.text == "10")) {
dialoguePanel.color = endDialogueBoxColor;
questText.GetComponent<Text> ().text = questName;
textBoxOnCheck = true;
questText.GetComponent<Text> ().text = questName;
messageBox.SetActive (true);
textBox.GetComponent<Text> ().text = messageText;
messageText = "Thank you so much for saving us from God's wrath. We have arranged a warp for you.Good luck traveller!";
questText.SetActive (true);
GameObject.Find ("Player").GetComponent<FirstPersonController> ().enabled = false;
} else {
textBoxOnCheck = false;
messageBox.SetActive (false);
questName = "Enter the warp";
talkProgress = true;
GameObject.Find ("Player").GetComponent<FirstPersonController> ().enabled = true;
questNameText.text = questName;
questNameText.text = "Enter the warp";
}
}
void Update () {
if (questNameText.text == "Enter the warp") {
Debug.Log ("Worked");
}
}
}
Everything works perfectly except line 22, 35, 39. Any help please?
What you want to happen is all in your Else block of code.
All of that code should just be on the bottom of your If block of code at around line 30.
I don't see the reason for your Else statement, you will only reach your Else block of code if either textBoxOnCheck is true or ringCountText.text is not "10". But everything you want to happen is in your Else statement when it really should be part of your If statement. You don't need an Else statement.