Getting stats from a list of scriptable objects

I’m very new to all of this, so apologies if the answer to this is easy.

I am working on a party-based game, where the player has six units. I have the units set up as scriptable objects, each with their own attack, defense, and other stats.

However, when entering a battle, I want to use the party’s stats as a whole to face off against the enemy.

I don’t know how to have this calculated from all six of the units.

I have a script for the player’s party that has the below set up, but I don’t know how to set the party’s attack stat equal to that of all of the individual unit’s attack stats added together:

public class PlayerTeam : MonoBehaviour
{
    [SerializeField] List<Unit> units;



    //Stats
    int serving { get; set; }
    int setting { get; set; }
    int attacking { get; set; }
    int blocking { get; set; }
    int defense { get; set; }
    int maxStamina {  get; set; }

    [SerializeField] List<KnownAttack> knownAttacks;
    [SerializeField] List<KnownBlock> knownBlocks;
    [SerializeField] List<KnownDefense> knownDefenses;
    [SerializeField] List<KnownServe> knownServes;
}

Any help is greatly appreciated. Like I said, I’m new to all of this so talking to me like a baby would be appreciated!

What part are you struggling with?

  • how to iterate a collection and sum it up?
  • how to sum other numbers?
  • basic C# syntax??

For this purpose ScriptableObjects are simply bags of data that you can edit in the inspector, so you can consider them simple object references for the purpose of syntax / design.

Otherwise, this might be useful to you:

ScriptableObject usage in RPGs:

Usage as a shared common data container: