// Can be called from the editor and amount be chosen. An UI button's OnClick can call this for example. public void ReceiveXP(int _amount) { // Add XP to the receiver without a granter. // ReceiveXP() returns a bool that can be used to check if the object has added the XP to their acquired XP. bool _gainedXP = XPCalculationMethod.ReceiveXP(_amount, null); if (_gainedXP) { Debug.Log(name + " is granted " + _amount + " XP."); } }
// Cannot be called by an UI button's OnClick for example, but other scripts can still call it as normal. // This is because OnClick doesn't support return types, only Void (which is why the other method is added). public bool ReceiveXP(int _amount, GameObject _granter = null) { // Add XP to the receiver with a granter. // ReceiveXP() returns a bool that can be used to check if the object has added the XP to their acquired XP. bool _gainedXP = XPCalculationMethod.ReceiveXP(_amount, _granter); if (_gainedXP) { Debug.Log(name + " is granted " + _amount + " XP by " + _granter.name + "."); } // Continue the chain of returning the boolean value XPCalculationMethod.ReceiveXP(). return(_gainedXP); }