How to attach a slider to a object in a diffrent scene

so i have to make a slide to control my x axis sensitivity for my new andriod game but the issue is I have different scene for the game and the menu and i have the player ( with whose the touch script is attached ) in the game scene but the slider in the menu scene and i cant find a way to attach the slider to the touch script

Here are 2 ways to access the value

  1. Use a Singleton that stores the slider value. Here is a basic example of how it would work.

First Create a singleton class and add it on a game object in Menu scene

public class GlobalControl : MonoBehaviour
{
    public static GlobalControl Instance;
    public float sliderValue;

    void Awake() 
    {
        if (Instance == null) 
        {
            DontDestroyOnLoad(gameObject);
            Instance = this;
        }
        else  
        {
            Destroy(gameObject);
        }
    }
}

Now when value of slider changes update the sliderValue variable of GlobalControl Script.

public class SliderScript : MonoBehaviour 
{
    public Slider slider;

    private void OnEnable()
    {
        slider.onValueChanged.AddListener(OnValueChanged);
    }
    
    private void OnDisable()
    {
        slider.onValueChanged.RemoveListener(OnValueChanged);
    }

    public void OnValueChanged() 
    {        
        GlobalControl.Instance.sliderValue = slider.value;
    }
}
  1. Another way is to store the slider’s value, and load it when needed. You can use PlayerPrefs for saving and loading. You can also save data in JSON format on disk.
public class SliderScript : MonoBehaviour 
{
    public Slider slider;

    private void OnEnable()
    {
        slider.onValueChanged.AddListener(OnValueChanged);
    }
    
    private void OnDisable()
    {
        slider.onValueChanged.RemoveListener(OnValueChanged);
    }

    public void OnValueChanged() 
    {
        // Here we are saving slider value
        PlayerPrefs.SetFloat("Slider Value", slider.value);
    }
}

To Load saved value use PlayerPrefs.GetFloat("Slider Value");
This will return the saved value of slider

Another way to save/load data is by using JSON file saved on disk