I'm new to coding games, so my logic may not be right for creating stats.
Quick intro: I'm creating a game that spawns units at the players command that go fight other units. To store all the different units stats I am creating a statsheet then (trying) to search that stat sheet in the units entity script that defines everything about that unit. I have an entity prefab that has all the scripts that apply to all units (such as move and damage). Then after the GameManager spawns the entity prefab, it builds another prefab (which is the actual unit) and moves it as a child inside the entity prefab.
I'm trying to add stats to each unit so I built a statsheet that holds non-MonoBehaviour classes with the different unit stats. The entity script then takes the name of the child(which is the unit name) and subtracts "(clone)" from it, then I want it to search for that class inside the statsheet based on that unit name and then assign the stats based of the preset stats in the statsheet. I don't know if this is the best way, or even a possible way at all. But so far logically it's the best I can come up with. I'm open to any suggestions if this won't work, however, the issue I'm running into with my current method is I can't search a class in another script based off a string. I've been searching the web for about 2 hours now and can't find anything.
entity script snippet:
public class Entity : MonoBehaviour
{
public Movement movement;
public int health;
public int damage;
public int attackSpeed;
public int range;
public int moveSpeed;
public bool flying;
public int cost;
private void Start()
{
movement = GetComponent<Movement>();
string unitName = transform.GetChild(0).name;
unitName = unitName.Remove(unitName.Length-7);
//unitName for this example returns "Pen1"
health = unitName.health;
}
here is my statsheet snippet:
public class Pen1
{
public int health = 50;
public int damage= 5;
public int attackSpeed = 1;
public int range = 1;
public int moveSpeed = 1;
public bool flying = false;
public int cost = 50;
}