'Unity EditorGuiLayout change slider properties depending on other values
I want to make a custom inspector script for my script. I need two gameobjects and a slider. However, the sliders max value is depending on the distance between the two gameobjects. I am using EditorGUILayout (Editor). Until now i tried to change it with an EditorGUI.BeginChangeCheck() and an if statement if (EditorGUI.EndChangeCheck()){...}. However, that doesn't really work and the slider does not show up. I am doing everything in the OnInspectorGUI() method. I am new to this, so I also don't really know what other things i can do.
Here is the code:
public override void OnInspectorGUI()
{
UILineRenderer renderer = (UILineRenderer) target;
EditorGUI.BeginChangeCheck();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Points");
renderer.startTR = (GameObject) EditorGUILayout.ObjectField(renderer.startTR, typeof(GameObject), true);
renderer.endTR = (GameObject)EditorGUILayout.ObjectField(renderer.endTR, typeof(GameObject), true);
EditorGUILayout.EndHorizontal();
if (EditorGUI.EndChangeCheck())
{
if(renderer.startTR != null && renderer.endTR != null)
{
float val = Mathf.Abs(renderer.startTR.GetComponent<RectTransform>().anchoredPosition.x - renderer.endTR.GetComponent<RectTransform>().anchoredPosition.x);
renderer.radius = EditorGUILayout.Slider("Radius", renderer.radius, 0, val);
}
}
}
Is there a way to save a createt EditorGUILayout element and change the properties of it afterwards? If not, how can I solve my problem? Thank you for your help in advance!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
