Question by
theXwhiteXnigga · Apr 07, 2017 at 03:04 PM ·
c#buttontextscene
how can i make the name of a clicked button appears as text in another scene
Hi guys, i made some buttons that changes the scene to another scene....all the buttons do the same job i.e changes to the same scene however i want to make a text that displays the name of the button the that was clicked....any ideas??
Comment
Answer by UnityCoach · Apr 07, 2017 at 03:18 PM
You can store it in a static member, that'll easily travel from a scene to the next.
public class ButtonTrigger : MonoBehaviour
{
public string thisText;
static public string commonText;
public void OnClick ()
{
commonText = thisText;
// load scene
}
}
public class TextDisplay : MonoBehaviour
{
void Start ()
{
GetComponent<Text>().text = ButtonTrigger.commonText;
}
}
Or use a static class to store a list of strings/values. I usually do this to store values across levels.
static public class GameDataStore
{
public static string lastClickedButtonText;
}