Conceptual Question - How best to Organize Many Data Types Used By Units

So, I’m working on an RTS type game. My units have health, attack, attack speed, shields, sounds, several sprites, special scripts, etc. How best do I organize all or most of these data types in a serial or numerical fashion? I’m about 3 weeks in coding C#. I’m starting to get a basic understanding of how to organize things. Not really enough to know how to do it the right way, but enough to know I’m probably just cobbling together what works and not really doing it correctly. My game works, but I was wondering, is there some way to organize ALL of the elements of my units, with these elements various data types, into some sort of array or other organizational tool where a number (such as “Unit #1”) could then draw every bit of information. In my mind it would be something like:

Where X is an integer:

Unit[X,0] = Name of unit X
Unit[X,1] = Tooltip of unit X
Unit[X,2] = Cost of unit X
Unit[X,3] = Character sprite of unit X
unit[X,4] = HP of unit X
etc

I realize the answer may be fairly straightforward, but like I said I’m still new to C# and I haven’t taken a computer programming course in about 10 years. Thanks for everything!

The advantage of an object oriented programming language is that you can create your own object with your own properties or fields based on a class. C# ist advanced for such things. You can manage the accessibility. I would recommend to write your own class. Do you want to insert faction 1 (the owner) with X for example?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class Unit
{

    public Unit(int playernumber, string nameofunit, string tooltipofunit, float costofunit, Sprite characterspriteofunit, float hpofunit) //The constructor
    {
        PlayerNumber = playernumber;
        NameOfUnit = nameofunit;
        TooltipOfUnit = tooltipofunit;
        CostOfUnit = costofunit;
        CharacterSpriteOfUnit = characterspriteofunit;
        HPOfUnit = hpofunit;
    }


    public int PlayerNumber;
    public string NameOfUnit = "";
    public string TooltipOfUnit = "";
    public float CostOfUnit = 0;
    public Sprite CharacterSpriteOfUnit;
    public float HPOfUnit;
}


public class NewBehaviourScript : MonoBehaviour {

    public Sprite SomeAttachedSpriteForExample;

    // Use this for initialization
    void Start ()
    {
        //For player 1
        var ForPlayer1 = new Unit(0, "Tank", "Tank", 10, SomeAttachedSpriteForExample, 100);

    }
 
    // Update is called once per frame
    void Update () {
    
    }
}

Or if you want to apply some business logic in the class.

  private bool isAlreadyDestroyed = false;
    private float hpofunit;
    public float HPOfUnit
    {
        get
        {
            return hpofunit;
        }
        set
        {

            if (isAlreadyDestroyed == true)
            {
                return;
            }

            hpofunit = value;

            if (hpofunit <= 0)
            {
                isAlreadyDestroyed = true;
                hpofunit = 0;
                // Destroy procedure for unit
            }

        }
    }

Or store it this way:

public class Player
{
    public string ThePlayer = "";
    public List<Unit> UnitsForThePlayer = new List<Unit>();

    public Player(string name)
    {
       ThePlayer = name;
    }



    public void AddUnit(Unit u)
    {
        UnitsForThePlayer.Add(u);
    }


}

I’d also like to recommend ScriptableObjects (SOs). They might confuse your thinking a little bit since you’re pretty new to programming, but they can be used as data assets as well as logic & algorithm providing assets. That’s really useful.

This allows to handle all the information in a single place. Of course, these would only represent the base-data. The units itself would reference one of these SOs and take the values as base-information. For per-instance state, you’ll then go with something similar to what has already been suggested in the previous reply.

Wow thank you so much for the great replies! This is very helpful. I’ll look at Scriptable Objects and the examples you provided, Abeginner. Really appreciate it!