In my scene, there are one InputField and 3 buttons.
There is text in a placeholder of the InputField: Hint1 / Hint2 / Hint3.
And names of each button are Hint1Btn, Hint2Btn, Hint3Btn.
What I want to do is:
Click Hint1Btn → text in placeholder change to pink / Hint2 / Hint3
Click Hint2Btn → text in placeholder change to Hint1 / 4 / Hint3
Click Hint3Btn → text in placeholder change to Hint1 / Hint2 / male
This is what I’ve written until now.
First , I split the text of the placeholder into 3 parts.
And I made a function that gives events to each button that make them able to change the text.
public InputField hintField;
string[] split_hintText;
void Start()
{
split_hintText = hintField.placeholder.GetComponent<Text>().text.Split('/');
for(int i = 0; i < split_hintText.Length; i++)
{
print(split_hintText[i]);
}
}
public void ShowHint()
{
string hintBtnName = EventSystem.current.currentSelectedGameObject.name;
if(hintBtnName == "Hint1Btn")
{
split_hintText[0] = "pink";
}
if(hintBtnName == "Hint2Btn")
{
split_hintText[1] = "4";
}
if(hintBtnName == "Hint3Btn")
{
split_hintText[2] = "male";
}
}
But the text in the placeholder doesn’t change at all when I click each button.
The code itself has no error. I think the logic has problems.
I assume that
split_hintText[0] = “pink”;
split_hintText[1] = “4”;
split_hintText[2] = “male”;
those codes just change strings of the ‘string[ ] split_hintText’ array and they don’t apply to the text of the placeholder. (like “Hint1” → “pink” and the end)
What should I do? I am stuck with this problem.