In a C# Unity script, how can I add fields that will be displayed in the Unity Inspector with min and max values on a single line? (like it is done for the Particle System, where you can choose Between Two Constants)

WHAT I HAVE | Separate lines for min and max:

enter image description here

public class MyTest : MonoBehaviour {
    [SerializeField] float projectileRateMin = 1f;
    [SerializeField] float projectileRateMax = 3f;

WHAT I WOULD LIKE: Single line with both min and max:

enter image description here

Another example is Vector2, which also gets displayed in the Inspector on one line. I did look at the Vector2 code and tried to copy and rename the relevant parts of the Vector2 struct to my own version, but it didn't show up in the Inspector at all.


1 Answer 1


Use the GUILayoutclass for drawing inspector and editor windows.

//the two lines you already have
  • \$\begingroup\$ I think there's another way for drawing Vector3s and the like, but I'm blanking on what it is. \$\endgroup\$ Jan 1, 2019 at 1:23
  • \$\begingroup\$ Error: The name 'BeginHorizontal' does not exist in the current context. Show potential fixes: Feature 'tuples' is not available in C# 4. Please use language version 7.0 or greater. It's a fresh Unity and Visual Studio installation. Do I need to update this and will it affect other areas of my project? \$\endgroup\$
    – Ben
    Jan 1, 2019 at 1:36
  • \$\begingroup\$ @Ben this looks like you've made an error in applying Draco18s's suggestion. Try editing your question to show the code you used. You were writing a custom editor or property drawer, right? \$\endgroup\$
    – DMGregory
    Jan 1, 2019 at 2:10
  • \$\begingroup\$ @DMGregory Question updated. I would like to display two value on one line, as shown in the screenshot for the particle system component. Another example is Vector2, which also gets displayed on one line in the Inspector. \$\endgroup\$
    – Ben
    Jan 1, 2019 at 2:27
  • \$\begingroup\$ @Ben I didn't ask you to repeat your question here in the comments. I asked you to show how you tried applying Draco18s's suggestion, including GUILayout in an editor script. \$\endgroup\$
    – DMGregory
    Jan 1, 2019 at 2:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .