void SetField(object obj, string fieldName, long value) { Type objType = obj.GetType(); FieldInfo fieldInfo = objType.GetField(fieldName, (System.Reflection.BindingFlags) ~0); if (fieldInfo.FieldType == typeof(long)) { fieldInfo.SetValue(obj, value); } else if (fieldInfo.FieldType == typeof(int)) { fieldInfo.SetValue(obj, FixedMath.RoundToInt(value)); } else { Debug.Log(string.Format("Field '{0}' of type '{1}' is not valid", fieldName, objType)); } }