- Home /
Question by
IsiahDaBoss67 · Oct 15, 2020 at 11:26 PM ·
inspectorvariablesdropdown
Creating a dropdown menu for variables?
I'm looking to create a dropdown to organise my variables in the inspector, im not looking for an enum, I'm looking for something like the info and constraints tab in RigidBody. Is this possible?
Comment
Best Answer
Answer by Namey5 · Oct 16, 2020 at 06:14 AM
If you don't want to create a custom editor, then an easy way of doing this is to just group your variables into a struct;
public class TestClass : MonoBehaviour
{
[System.Serializable]
private struct VariableGroup
{
public float testFloat;
public int testInt;
public VariableGroup (float a_TestFloat, int a_TestInt)
{
testFloat = a_TestFloat;
testInt = a_TestInt;
}
}
[SerializeField] private VariableGroup m_Variables = new VariableGroup (4.5f, 2);
}
Answer by Getsumi3 · Oct 16, 2020 at 07:35 AM
Hello. If you mean "a dropdown menu" just a way to group your variables and be able to hide/show them in inspector than take a look at this example:
public class TestClass : MonoBehaviour
{
public TransformData t_data;
private void Start()
{
t_data.x = 1;
t_data.y = 2;
t_data.z = 3;
}
}
[System.Serializable]
public class TransformData
{
public float x;
public float y;
public float z;
}
Thanks, this is exactly what I was looking for!, I can't accept you answer however because somebody else answered first :[