Sorry for the title, I could not imagine a more specific title but let me explain.
Let's say we have 2 different characters. One is Ally which is our character and the other one is Enemy. And let's say we are immortal so Ally cannot die.
public class Ally : BaseCharacter
{
public override void Attack() { }
}
public class Enemy : BaseCharacter
{
public void Die() { }
public override void Attack() { }
}
public class BaseCharacter
{
public BaseCharacterData baseCharacterData;
public virtual void Attack() { }
}
Here, Attack() function is common between these child classes. But Die() function is not.
And we have data classes for these classes.
public class AllyData : BaseCharacterData
{
}
public class EnemyData : BaseCharacterData
{
public string health;
}
public class BaseCharacterData
{
public string name;
}
And also here, NAME variable is common and HEALTH is not (cuz Ally cannot die).
The problem is this, when I try to create BaseCharacter from another script I assign CharacterData to Ally and it's just fine.
But when I create Enemy, Enemy's health will not be set (I can set it from somewhere else somehow maybe but it's a problem when I need to reach it as well). Also, let's say we have another class called TEMP and one of its functions takes CharacterData. But it will not be able to reach HEALTH if that CharacterData belongs to an Enemy or it will not be able to call Die() function from BaseCharacter script of Enemy cuz its not common.
This whole scenario is not a real one and does not make sense but I try to simplify it and tell what my problem looks like.
My question is, Is there something I'm doing wrong or this scenario just need a better structure to achieve my goals?
I'm open to all suggestions or solutions but I'm not trying to solve my problem easily or solve it in bad ways. Just trying to find the right ways.
Thank you all in advance.