How to use the name of the button as a value of a variable?
After days of searching and modifying my code with little to no success, it seems that I found the problem that is making my agony on C# scripting longer - and that is when the button is pressed, a variable has not been filled up by EventSystem.current.currentSelectedGameObject.name. I did this in order for the text at the next scene be changed depending on the button pressed at the previous scene (in this case, I can't make it change because of the problem stated above)
Did I missed something, which is why the variable is not filled up? The concept is like this, ButtonText == EventSystem.current.currentSelectedGameObject.name; and the button displayed on Debug.Log() test is "Tutorial Button", that will be used as the value for ButtonText?
Long story short, although it is possible that I can create scenes that cater to each experiments that will be simulated on an AR and build it manually, but I want to simplify everything because it will be a heavy overload if I do that. So, I looked at C# scripting and here are the code snippets:
ButtonScript.cs
protected string TextButton;
//When pressed, ButtonPress() will be triggered and will go to Experiment Information Scene
public void ButtonPress(){
TextButton = EventSystem.current.currentSelectedGameObject.name;
SceneManager.LoadScene(5);
}
DisplayScript.cs
switch (TextButton) {
case "Tutorial Button":
ExpNum.text = "Tutorial";
ExpTitle.text = "Coke With Mentos Experiment";
ExpDetails.text = "//Details will be shown here";
break;
}
Any help is appreciated. Thanks!
Your answer
Follow this Question
Related Questions
Matching Button ID to information displayed on GameObject 0 Answers
how to add a button example (tap to flap) 0 Answers
How to make button click continuous ? 0 Answers
With the new unity input system. How do I setup UI buttons like in the old system. 0 Answers
how to make sound settings button? 1 Answer