Get a float transferred between two scenes and scripts

I have two scenes, one where you type in the speed of a car via Input Field, and the next one, with a car with a script attached to it, with the float “speed”.

Script Nr. 1:

public static class Data
    private static int speed;

    public static int Speed
            return speed;

            speed = value;

And Scipt Nr. 2:

public class Driving : MonoBehaviour {

    float speed=0f;

I’m just a beginner and tried the whole day, my first try with script 1 was this:

public class Data : MonoBehaviour {

    static public float speed=10f;

    public InputField speedField;

    void OnSubmit()
        speed = float.Parse(speedField.text);
  • But some guys on Srtack Overflow told me I should make it not this way. I don’t understand where I have to attach the first script and how I transfer speed from scene 1 to scene 2 and from script Data to Driving.

Good day.

You should look some tutorials about data persistance, to transfer info between scenes.

Good bye.

this is all you need:

public class SharedSavedStuff{

	public static float sharedfloat;

I would put it OUTSIDE the monobehavior brackets. Or in a new script and get rid of the part that says" : MonoBehaviour"

you dont even need to attach it to anything!

the variable can be accessed from anywhere from any other script and it wont be affected by scene reloads and things like that.

you access it by saying:
SharedSavedStuff.SharedFloat = 12674.3f;

You should use ScriptableObject. Using ScriptableObject for Data architecture / sharing