Make Multiple Classes from within one script

I don’t think I explained it well enough last time I made a thread so I am going to go a different route this time.
I know how to save data and use scriptable objects, that’s not what I’m asking to know about.
Say I have a baseclass and I want to have several characters throughout a game you use in battle. I would need to in battle save it to game information.
I’ve tried in multiple ways to contain multiple classes based of let’s say “BaseClass”, but even when I make it static, I can’t reference or change it from other scripts. I’ve tried looking up inheritance and stuff but I don’t know the exact way you’re supposed to code it, and I can’t find any good reference code to use to figure out how to do it.
Does anyone have any good reference code for this?

So, you want to do something like this?

File: BaseFoe.cs
public class BaseFoe : MonoBehaviour {
 ...
}

File: Foe1.cs
public class Foe1 : BaseFoe {
 ...
}

@Kronnect Something similar, yes. My issue is I am not sure how to create a new “BaseClass” and store it onto GameManager.

This could be a skeleton:

File: IFoe.cs
public interface IFoe {
  ... (the contract or mandatory methods/properties for any type of foe)
}

File: BaseFoe.cs
[Serializable]
public class BaseFoe : IFoe {
... common fields to all foes
}

File: SpecialFoe.cs
[Serializable]
public class SpecialFoe : BaseFoe {
  ..:.
}

And in GameManager add:

public List<IFoe> gameFoes;

Which you can serialize/deserialise using jSON.

Now, your game objects could have a script attached to store individual foe data like this:

public class FoeBehaviour : MonoBehaviour {
   public IFoe foeData;
  ...
}

So you have easy to access foe data per game object and also they belong to a global list of foes which you can use to manage them together.

Not sure if this is what you’re looking for - perhaps you can provide some context and sample code.

let’s say that this is the base class

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

public class ActorBase : MonoBehaviour {
    //``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
    //RPG STATS
    //public string secondName; //ignore anything with "sec" or "second" for the time being
    //public string className;
    //public string secClassName;

    //public int baseHP;

    public BaseClass actor;

    public BaseAttack nAttack;
    public AttackList skillListOne;
    public AttackList skillListTwo;

    public string actorName; //character name
    public int mHP; //max HP
    public int mMP; //max MP
    public int maxDrive;

    //In battle I might intend for enemies to be able to lower your maximum health, so in battle/wherever you
    //are able to take damage, it to work with these.
    public int aCurHP; //current hp. hp = 0 you're dead
    public int aCurMP; //current mp
    public int aCurDrive; //you would probably start a battle with 0 I assume.

    public int enMuscle; //strength
    public int enWill; // defense/magicdefense
    public int enInstinct; //same thing as evasion. Higher = more hits on enemy and less hits from enemy.
    public int enAgility = 10; //how quick they get turn

    //in battle if someone uses a skill to reduce a specific stat, I intend for it to use your current stat
    //- when doing calculations in battle. When battle ends I intend to make curStat = Stat
    //(example: curMuscle = muscle when a battle begins and ends)

    //Affinities to elements
    //> 1 increases damage, 1 < & > 0 lowers damage.
    //1 = normal damage, 0 = immune
    // < 0 heals instead of damage
    public int sA = 1; //solarAffinity
    public int lA = 1; //lunarAffinity
    public int cuA = 1; //CurreneAffinity
    public int tA = 1; //TerreneAffinity
    public int pA = 1; //pyroAffinity
    public int cA = 1; //cyroAffinity
}

Let’s say in GameManager I want to manage several characters at once and store them in GameManager. I don’t know how else to explain this.

1 Like