How can i make a Range slider to control two variables ?

[Range(3, 100)]
public int mapWidth = 10;
[Range(3, 100)]
public int mapHeight = 10;

I want to do that when i change the value with the slider in the Inspector of mapWidth it will change also the value of mapHeight and same if i change the mapHeight. Or to disable not to hide the mapHeight range slider so it will move when moving the mapWidth range slider but the user will not be able to change the mapHeight only with the mapWifth.

I need this since i want that always the values in mapWidth and mapHeight will be same.

You could try this:

[Range(3, 100)]
public int mapWidth = 10;

public int mapHeight { get { return mapWidth; } }

Or you could write a custom inspector that changes both when you change one.

2 Likes

How can i use the:

public int mapHeight { get { return mapWidth; } }

Inside the OnValidate.
I can put this line in the top of the script but then when i change mapWidth slider it will not update the mapHeight.

This will do that, but why even make height a slider at that point?

[Range(3, 100)]
public int mapWidth;
[Range(3, 100)]
public int mapHeight;

private void OnValidate() {
    mapHeight = mapWidth;
}

As for being able to change either and the other one mirror the value, you’d need to store the “current” value and then detect which one changed, and change the other one to match.

1 Like

Thank you in the end i’m using one global variable mapSize with Range. And i create the map/grid onlt with the mapSize so i don’t need to update other variables and not using OnValidate.