Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TextFieldController : MonoBehaviour
- {
- public GameObject GameControllerReference; //Reference to the GameController. Must be defined in the Inspector.
- public List<string> FieldsToDisplay; //A list of the fields to display in this text element. They will be separated by new lines.
- // Start is called before the first frame update
- void Start()
- {
- if (GameControllerReference == null)
- Debug.LogError("Game Controller reference not set on this TextController.");
- }
- // Update is called once per frame
- void Update()
- {
- string textToDisplay = ""; //The text we will eventually display will be stored in this.
- if (FieldsToDisplay[0] == "score") //If the first field is "score"...
- textToDisplay = "Score: " + GameControllerReference.GetComponent<GameController>().GetScore().ToString(); //Ignore everything else and use this text box as a score display.
- else //Otherwise...
- {
- foreach (string field in FieldsToDisplay) //For each field that we want to display...
- {
- foreach (string type in GameControllerReference.GetComponent<GameController>().GetProfileFields()) //For each type of field...
- {
- if (field.Equals(type)) //If this is the field we need...
- {
- int index = GameControllerReference.GetComponent<GameController>().GetProfileFields().IndexOf(field); //Get the index of this type of field.
- textToDisplay = textToDisplay + GameControllerReference.GetComponent<GameController>().GetCurrentProfile()[index] + "\n"; //Use that index to get the value from the current profile, and append it to the text to display, plus a new line.
- }
- }
- if (field.Equals("all")) //If any field is "all"...
- {
- textToDisplay = textToDisplay + GameControllerReference.GetComponent<GameController>().GetCurrentProfileString() + "\n"; //Dump all the fields at this position.
- }
- }
- }
- gameObject.GetComponent<TextMesh>().text = textToDisplay; //Change the text of the TextMesh to match what we want to display.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment