Is it possible to get all of the public variables from a custom component script attached to a GameObject? If so, how is it done without any custom methods?
You can use Reflection:
const BindingFlags flags = /*BindingFlags.NonPublic | */BindingFlags.Public |
BindingFlags.Instance | BindingFlags.Static;
FieldInfo[] fields = obj.GetType().GetFields(flags);
foreach (FieldInfo fieldInfo in fields)
{
Debug.Log("Obj: " + obj.name + ", Field: " + fieldInfo.Name);
}
PropertyInfo[] properties = obj.GetType().GetProperties(flags);
foreach (PropertyInfo propertyInfo in properties)
{
Debug.Log("Obj: " + obj.name + ", Property: " + propertyInfo.Name);
}