Pobieranie tekstu z pola inputfield TMPro w Unity

using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class NapisComponent : MonoBehaviour
{

    [SerializeField] TextMeshProUGUI tekst1;
    [SerializeField] Button btn;

    [SerializeField] TMP_InputField inpWriting;

    public void ChangeText()
    {
        // Pobiera dane wprowadzone w inputfield i wyświetla je jako tekst przycisku
        // Funkcja jest wywoływana w inspektorze przy każdej zmianie wartości
        tekst1.text = inpWriting.GetComponent<TMP_InputField>().text;
        btn.GetComponentInChildren<TMP_Text>().text = tekst1.text.Replace("\n", "");
    }
}
Ask ChatGPT
Set ChatGPT API key
Find your Secret API key in your ChatGPT User settings and paste it here to connect ChatGPT with your Tutor LMS website.
Scroll to Top