Changing the string of multiple buttons when one button is clicked? (newb)
Here's my script, I want to change the string of multiple text objects depending on the value of a variable. This variable is suppose to change when a button is clicked, but I have trouble figuring out how to change the string of a button on runtime, this script isn't run in the text object itself but in an empty and needs to be called by the button, this is what is making it confusing for me I think.
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class DialougeScript : MonoBehaviour {
int one;
int two;
int three;
int four;
public Text text;
Text text1;
Text text2;
Text text3;
Text text4;
// Use this for initialization
void Start () {
text1 = GetComponent<Text>();
text2 = GetComponent<Text>();
text3 = GetComponent<Text>();
text4 = GetComponent<Text>();
one = 1;
two = 1;
three = 1;
four = 1;
Dialouge();
}
public void Dialouge () {
print ("test");
if (one == 1){
text.text = text1.ToString("Hello who are you?");
if (two == 1){
text.text = "I'm lost, where are we?";
if (three == 1){
text.text = "I wish I had something to eat.";
if (four == 1){
text.text = "I've got to go I think.";
}
}
}
}
}
// Update is called once per frame
void Update () {
}
}
This is what I'm confused about
" if (one == 1){ text.text = text1.ToString("Hello who are you?");"
and probably about other things as well such as what needs to be declared or called. I found the get component lines online, not sure if you're suppose to use those. Anyone knows how to do this? If I know how to change the string of a button I'm quite sure I could figure out the rest myself.
Your answer
Follow this Question
Related Questions
Change Player "Avatar" to a other "Avatar" by a GUI button click? 0 Answers
How to maintain button graphic on change scene? 0 Answers
Variable value does not change 0 Answers
click the button to change the character's sprite 1 Answer
How to change a public location,how to get a public variable 1 Answer