Using Buttons to write numbers

Hello everyone. So I have 10 buttons labled with the numbers 0-9, I managed to let the buttons write their numbers into a textfield when I click on them (with the simple OnClick event implemented in unity), but everytime I click on a new button, the previous number gets overwritten and I need it to remain to be able to show numbers like 12, 34 and so one. Unfortunately I dont even know how to properly start the C# Script for that. I hope that some of you can help me. ^^

When you assign the button value to your textfield add it instead of assigning it.

Like: textfield.text += string.Format(“{0}”, button.text);

Hello @TheNicojack :

As @OneCept-Games says, you can use this “formula”

FinalText.text = FinalText.text + NewText.text;

so the new characters will be writen after the old characters.

This "formula is exactly the same as this (short way)

FinalText.text += NewText.text;

This ( + = ) can be used with all variables like int or float, to add or remove ( - = )

you can also check the length of the string variable to decide if want to create a new string or continue adding the new text to the old with:

int NumberOfCharacters = FinalText.text.Length;

For remove characters from a string variable you need to use

string NewText = FinalText.text.Substring (int StartIndexCharacter);

More info in SubStrings - Questions & Answers - Unity Discussions

Good luck with your project!

@tormentoarmagedoom
@OneCept-Games
Thanks for the help ^^ now my code looks like this:

public class T1Btn : MonoBehaviour {

public Text FinalText;
public Text Btn1;
public Text Btn2;



void ButtonText()
{
    FinalText.text = FinalText.text + Btn1 + Btn2;
}

}

but it isn’t working, can you tell my hat I am doing wrong ?