Using GUI.HorizontalSlider on Vector2?

Hello! I am attempting to create a Sensitivity Slider with GUI.HorizontalSlider by grabbing the values from another script’s line: public Vector2 MouseLookSensitivity = new Vector2(5.0f, 5.0f);

I’m getting the error cannot convert 'UnityEngine.Vector2' expression to type 'float' and I would like some guidance on what to do differently to achieve my goal. :slight_smile:

The error means exactly what it says.

The variable MouseLookSensitivity is a Vector2:

On the other hand, GUI.HorizontalSlider is a float:

You can’t set a float to a Vector2.

Why exactly do you need the MouseLookSensitivity variable for? It has two floats since it’s a Vector2. Do you perhaps want to use them as position values? Or slider values for the GUI.HorizontalSlider? Look at the parameters for GUI.HorizontalSlider closely.

As an alternative approach, if you intend to have a single “sensitivity” scale for both X and Y axes, you can use a float to maintain your entire sensitivity and multiply the Vector2 by that value.

float mouseLookSensitivity;
Vector2 mouseScale;

void OnGUI()
{
	mouseLookSensitivity = GUI.HorizontalSlider(**DETAILS HERE**);
	mouseScale = Vector2.one * mouseLookSensitivity; // Vector2.one used under the assumption of equivalency
}

mouseScale may not even be necessary, depending on implementation. Alternatively, mouseScale could also be given two separate values to provide a different degree of sensitivity to each axis.