Need help with very difficult solution (Saving)

I’m pretty advent on solving my own problems and I’ve come a long way with C# in just a couple months. Now, however, I have hit a wall. It’s going to be hard to show you examples as I’m running about 30 scripts right now and a hierarchy / inheritance system.

http://puu.sh/atTME/1926fde149.png In my hierarchy, I have these enemies which are assigned to a list. This list is used to instantiate the enemies into the scene instead of instantiating from prefab. There are no scene changes btw.

I have a level up system for each enemy that happens after every 3 waves which I do like this:

 if (_levelCounter % 3 == 0)
        {
            for (int i = 0; i < 5; i++)
            {
                grabNormalEnemies[i].MStatSet.LevelUp();
                print(grabNormalEnemies[i].name + " " + grabNormalEnemies[i].MStatSet.Health.Max);
                _levelStopper++;
                if (_levelStopper == 5)
                {
                    _levelCounter++;
                }
            }
        }

According to the print, the health stat is increasing. However, the actual value I have showing on the object remains unchanged.

 void Awake()
    {
        disableMovement = true;
        _dmgShow = "Critical Hit!" + "\n" + (_gunPowMaxDesu * 3).ToString();
        showDMG.text = _dmgShow;
        showDMG.text = "";
        _moveDesu = Random.Range(1, 5);
        _statSet = Zombie1Stat.zombie1Spawn();
        _shootAnimCur = (MStatSet.moveSPD.Max * MStatSet.moveSPD.Current) / MStatSet.moveSPD.Max;
        animation["Walk"].speed = _shootAnimCur;
        print(MStatSet.Health.Max);
    }

As you can see, when the new enemy instantiates, I have a print to show me its health max. It still shows the base value despite the level up happening.

public void LevelUp()
    {
        Health.EnemyIncrease();
        armor.EnemyIncrease();
        Power.EnemyIncrease();
        moveSPD.EnemyIncrease();
        points.EnemyIncrease();
    }

Here is my levelup method in the 2nd part of the hierarchy. The base class is here (which uses getters and setters)

 public void EnemyIncrease()
    {
        Max += IncreaseRate;
        Current = Max;
        if (Max <= Min)
        {
            Max = Min;
        }
        if (iMax > 0)
        {
            iMax += iIncreaseRate;
            iCurrent = iMax;
        }
    }

Since I am instantiating from the hierarchy, not prefabs. I’m wondering why my level up is not actually saving the values that it is changing to the object itself? Why are my enemies still showing the base stats and not actually changing at all?

Please ask specific questions if you need more info. I have a lot of code written so I am trying not to clutter the post.

Saving what and where?

using UnityEngine;
using System.Collections;

public class Zombie1Stat
{
    public static StatSet zombie1Spawn()
    {
        StatSet zombie1Enemy = new StatSet();
        zombie1Enemy.name = "Zombie 1";
        zombie1Enemy.Health.IncreaseRate = 50;
        zombie1Enemy.Power.IncreaseRate = .25f;
        zombie1Enemy.armor.IncreaseRate = .25f;
        zombie1Enemy.moveSPD.IncreaseRate = .01f;
        zombie1Enemy.points.iIncreaseRate = 50;
        zombie1Enemy.Health.Max = 80;
        zombie1Enemy.Health.Current = 80;
        zombie1Enemy.Health.Min = 0;
        zombie1Enemy.armor.Max = 5;
        zombie1Enemy.armor.Current = 5;
        zombie1Enemy.armor.Min = 0;
        zombie1Enemy.Power.Max = 10;
        zombie1Enemy.moneyGain.iMax = 50;
        zombie1Enemy.moveSPD.Max = 1.5f;
        zombie1Enemy.moveSPD.Current = 1.5f;
        zombie1Enemy.moveSPD.Min = .9f;
        zombie1Enemy.points.iMax = 100;
        //zombie1Enemy.moveSPD.Current = 6f;
        //zombie1Enemy.moveSPD.Min = 0f;
        return zombie1Enemy;
    }
}

This is the stat script assigned to my zombie. When the zombie levels up, these stats are modified. The print() line in my “for” loop in the code I listed above shows the stats being changed, however the stats are never actually UPDATED on the object in my hierarchy (nor the prefab).

Every instance of your object is having a different instance of StatSet. I have a feeling your are trying to change only one instance of StatSet. You have to loop over all your instances to update them.

The level up changes the _statSet of these:

The for loop, loops through each element in this lost. When the objects are instantiated, they are instantiated from the elements of this list. So I am changing the enemies in this list with the level up and instantiating from this list.

I will show you how they are being instantiated (with a parameter called from another method):

 void SpawnEasyZombie(int _easyCountDesu)
    {
        switch (_easyCountDesu)
        {
            case 1:
                GameObject pullBear = grabNormalEnemies[0].gameObject;
                GameObject _createClone = Instantiate(pullBear, new Vector3(-8, 500f, -13), Quaternion.identity) as GameObject;
                _createClone.GetComponent<Zombie1>().enabled = true;
                _createClone.GetComponent<Zombie1>().disableMovement = false;
                enemySpawn.Add(_createClone);
                break;
            case 2:
                GameObject pullRabbit = grabNormalEnemies[1].gameObject;
                GameObject _createRabbit = Instantiate(pullRabbit, new Vector3(-8, .5f, -13), Quaternion.identity) as GameObject;
                _createRabbit.GetComponent<RabbitPoly>().enabled = true;
                enemySpawn.Add(_createRabbit);
                break;
            case 3:
                GameObject pullCat = grabNormalEnemies[2].gameObject;
                GameObject _createCat = Instantiate(pullCat, new Vector3(-8, 500f, -13), Quaternion.identity) as GameObject;
                _createCat.GetComponent<CatPoly>().enabled = true;
                enemySpawn.Add(_createCat);
                break;
            case 4:
                GameObject pullSkelly = grabNormalEnemies[3].gameObject;
                GameObject _createSkelly = Instantiate(pullSkelly, new Vector3(-8, .5f, -13), Quaternion.identity) as GameObject;
                _createSkelly.GetComponent<SkellyPoly>().enabled = true;
                enemySpawn.Add(_createSkelly);
                break;
            case 5:
                GameObject pullPenguin = grabNormalEnemies[4].gameObject;
                GameObject _createPenguin = Instantiate(pullPenguin, new Vector3(-8, 500f, -13), Quaternion.identity) as GameObject;
                _createPenguin.GetComponent<PenguinPoly>().enabled = true;
                enemySpawn.Add(_createPenguin);
                break;
        }
    }

An update regarding my problem here. The enemy in the hierarchy levels up, but when I instantiate a copy of that enemy, it will instantiate the enemy with base stats instead of the leveled up version.

I think this is because the object itself is having the stats altered but the base stat script remains unchanged and Unity instantiates a copy of the enemy but assumes the base stat script.

It seems to be the result of the hierarchy and inheritance system I’ve been using. I had to use a for loop and a counter that goes up every 3 wave numbers so the enemies, when spawned, will be at level 1 on wave 3, level 2 on wave 6 because the loop actually levels them up multiple times depending on where the counter is at.

I feel like this is very hackish though and may cause slowdowns if they are leveling 10+ times every time they spawn. There must be a better way but I’m finding explaining my situation to be difficult so I’m sorry about that.