Eonirr

Untitled

Mar 12th, 2025
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. public void IncreaseBuffStat<T>(T scriptableObject, string variableName, float amount) where T : ScriptableObject
  2. {
  3. if (scriptableObject == null) return;
  4.  
  5. Type type = scriptableObject.GetType();
  6. FieldInfo field = type.GetField(variableName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
  7.  
  8. if (field != null && field.FieldType == typeof(float))
  9. {
  10. float currentValue = (float)field.GetValue(scriptableObject);
  11.  
  12. field.SetValue(scriptableObject, currentValue + amount);
  13. }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment