How to pass a value from one script to another

1

In a scene I get the data entered by the user, once you enter the data with a button changes the scene but the problem is that I do not know how to pass that value to the other scene. the method where I get the value of the data and change the scene

public void closePanel()
    {
        int numeroid = int.Parse(inputFielEditar.text);
        new InicioSesion().cambiarScene(3);
        //gameObject.

        //panelEditar.SetActive(false);
    }

and in the other script that starts some data from the scene try the following to receive the data

public RegistroEjercicio(int numEjercicio)
    {
        this.numEjercicio = numEjercicio;
    }
    // Use this for initialization
    void Start () {
        if (numEjercicio !=0)
        {
            llenar();
        }

    }

The problem is that I did not find out how to fill that constructor and start it when changing the scene

    
asked by Richard Yordy 30.11.2018 в 13:00
source

1 answer

1

A very simple but unsafe option is the use of PlayerPrefs ,

Script of the Set:

public void closePanel()
{
    int numeroid = int.Parse(inputFielEditar.text);
    PlayerPrefs.SetInt("NumeroId",numeroid);
    new InicioSesion().cambiarScene(3);
}

Get script:

// Use this for initialization
void Start () {
   int numEjercicio = PlayerPrefs.GetInt("NumeroId");
   if (numEjercicio !=0){
      llenar();
   }
}
    
answered by 12.12.2018 в 17:24