How do I make sensitivity slider

I wanna make a slider that controls the cameras sensitivity across scenes (like a slider in the menu that controls the cameras sensitivity in a different scene)

my camera control script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraControl : MonoBehaviour
{
    public float sensitivity = 20f;
    public Transform playerBody;

    float xRotation = 0f;

   
    void Start() {
        Cursor.lockState = CursorLockMode.Locked;       
    }  
   
    void Update() {
        float mouseX = Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
        playerBody.Rotate(Vector3.up * mouseX);
    }


}

What have you tried so far?

Beginners’ tutorial how to preserve/persist data between scene loads if that’s what you’re looking for:

https://www.youtube.com/watch?v=WchH-JCwVI8

I’ve tried to reference the variable of “sensitivity” in my camera controller but idk how to reference prefab variables

There are no prefabs runtime. Everything is gameobject.

@ The video isn’t what I’m trying to do, it seems. I’m trying to access a variable from an object from a different scene, like a sensitivity slider in a settings menu scene that controls the cameras sensitivity in a different scene

Well, if you have both scenes loaded at the same time, then you just need to use GameObject.Find to find the slider. Or put the value in a static variable if you prefer that.

1 Like

that should work I’ll try that, I might also use [DontDestroyOnLoad] and get the value of the slider. then I can replace the cameras float value with the value stored in the script

ok I tried the idea of making the sensitivity value a static value and making it = the sensitivity sliders value! thanks!

my code incase anybody wants to know:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraControl : MonoBehaviour
{
    public static float sensitivity = 200f;
    public Transform playerBody;

    float xRotation = 0f;

   
    void Start() {
        Cursor.lockState = CursorLockMode.Locked;       
    }  

    public void SensStored (float sensIndex) {
        sensitivity = sensIndex; 
     }

    void Update() {
        float mouseX = Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
        playerBody.Rotate(Vector3.up * mouseX);
    }


}