I have several objects that contain child objects. They look like this:
mainObject (Field script attached, has a local variable called strength)
1
2
3
4
5
Now there is a connection between a value in mainObject (strength) and which of those objects 1-5 are active. Because I need this for leveldesign and there are a lot of those 1-5 objects, I cannot activate them by hand. I want to select the mainObject and then have a slider that will automatically enable/disable the child objects.
Is this possible in the Editor and if yes, how? I want the changes to be reflected during editor time. Otherwise I could script that easily of course.
Basically you can create a custom inspector for your Field script that will present a slider (with a given range of 1 - 5). Based on the selected value of this slider you can enable / disable any objects that are children of the game object that this script is on.
Let me know if you need further assistance with implementing this.
Hi, just a small hint: you forgot the UnityEditor import in your blog entry.
This is the end result which gives me a slider that will automatically activate and deactive the children:
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(Field))]
public class EasyLevelDesigner : Editor {
public override void OnInspectorGUI()
{
DrawDefaultInspector();
Field field = (Field) target;
int val = EditorGUILayout.IntSlider(field.getStrength(), 0, 5);
field.setToStrengthAndUpdateSprite(val);
}
private void OnModified(){}
}