Hey everyone,
I’m trying to hide or show variables according to the current state of an enum in an array - here’s the code of the concerned array.
public enum ActionType { Move, Shoot, RotateShoot, Wait, Explode, Replay };
public enum ShootType { Classic, Laser };
public EnemyPattern Pattern = new EnemyPattern();
[System.Serializable] public class EnemyPattern {
public List<PatternAction> state;
} [System.Serializable] public class PatternAction {
public ActionType Action;
[Header("For Action Move")]
[Range(2, 20)] public int Speed = 2;
public Vector2 distance;
[Header("For Action Shoot")]
public ShootType Shoot;
public GameObject ShotPrefab;
[Range(1, 50)] public int NumberShoot = 1;
[Range(1, 50)] public float ShootSpeed = 5;
[Range(0, 10)] public float TimeBetweenShoot = 0.2f;
[Header("For Action Rotate Shoot")]
[Range(-360, 360)] public float Rotation = 0f;
[Header("For Action Wait")]
[Range(0, 60)] public int TimeToWait = 0;
}
Also I have this code in the editor code :
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(EnemyController))]
public class EnemyControllerInspector : Editor {
override public void OnInspectorGUI () {
EnemyController script = (EnemyController)target;
EnemyController.PatternAction.Action = (EnemyController.ActionType)EditorGUILayout.EnumPopup("Action", EnemyController.PatternAction.Action);
for (int i = 0; i < script.Pattern.state.Count; i++) {
if (script.Pattern.state[i].Action == script.ActionType.Move) {
script.Pattern.state[i].Speed = EditorGUILayout.IntField("Speed", script.Pattern.state[i].Speed);
script.Pattern.state[i].distance = EditorGUILayout.Vector2Field("Test int", script.Pattern.state[i].distance);
}
}
}
}
The problem is that I don’t know how to access to the values, I know this is wrong but I don’t know how to do it correctly… May I have a bit of help ? Thank you !