Can anyone help me connect the inputfield of one script in the text of the other?

Scripts:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class LigacaoletreroLinha : MonoBehaviour {

    private letreroLinha other;
    public InputField inputField;

    public void Update()
    {
        other.ButtonClick();
    }
}
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using System.Text;
public class letreroLinha : MonoBehaviour {

    private static LigacaoletreroLinha inputField = new LigacaoletreroLinha();
    public Text myText;
    public Text myText1;
    public Text myText2;

    public void ButtonClick(){
        myText.text="" + inputField.text+ "";
        myText1.text="" + inputField.text+ "";
        myText2.text="" + inputField.text+ "";
    }
}

You shouldn’t create monobehaviours with the ‘new’ keyword.
A simple solution would be to have a button (or key) wait for a click/keyup event, and when that’s received, set the Text elements, as you’ve written there.
Instead of using the new operator, simply try: public LigacaoletreroLinha inputField;
and drag the inputfield to the slot inside the inspector.
(Unless you really, really need it to be static… in which case we could talk more about that). But try these steps, first.

I already tried not working

Can you post the updated code?

Instead of writing I could make a sample script because I’m not very good in English

Um. Cool :slight_smile: But you’ll have to write the script for me to read it :stuck_out_tongue:

Scripts:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class LigacaoletreroLinha : MonoBehaviour {

    private letreroLinha other;
    public InputField inputField;

    public void Update()
    {
        other.ButtonClick();
    }
}
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using System.Text;
public class letreroLinha : MonoBehaviour {

    public LigacaoletreroLinha inputField;
    public Text myText;
    public Text myText1;
    public Text myText2;

    public void ButtonClick(){
        myText.text="" + inputField.text+ "";
        myText1.text="" + inputField.text+ "";
        myText2.text="" + inputField.text+ "";
    }
}

Okay, so first of all … remove “other.buttonClick()” from the update function. You do not want or need it there.
Next, I may have given you some horrible advice a couple of posts back, so I will correct that :slight_smile:
In this script “letreroLinha”, change the inputfield to: public Inputfield inputfield
then, in the inspector, drag the actual inputfield you have into that spot on the script.
Then, you must have a button somwhere, right?
where it says OnClick() in the inspector, click the ‘+’ button.
Then, drag whichever object has : letreroLinha and use the drop down menu to say letrerolinha and the method “ButtonClick()”
Wow, hopefully that makes sense to you.

Could you explain me by giving small sample scripts because when I translate your speech by google it comes out all in a hefty way.

public class ButtonScript : MonoBehaviour{
public Inputfield inputfield;
public Text myText;
public Text myText1;
public Text myText2;

public void Clicked(){
myText.text = "" + inputfield.text ;
myText1.text = inputfield.text;
myText2.text = inputfield.text;
}
}

Add this to a button.
Drag all 3 Text to the script + the inputfield.
For OnClick() in the inspector, add a new event.
Drag the button to the gameobject part.
Use the drop down menu and choose Clicked().

Start game, type something in the inputfield. Click the button.

Look at this I had done at the beginning only that you did not understand how the script works. I am trying to do what, one script is for you to write and the other is going to take what is written and turn into text and just what I want.

Not sure what your last message said. I got the idea of what you wanted from the beginning, but it wasn’t working… I’ve only tried to offer some suggestions to get done what you were attempting to do.

1 Like