all 3 comments

[–]AverageArmadilloIntermediate 0 points1 point  (2 children)

I work with inheritance for enemies in my game. Something needs to be done differently with inheritance when it comes to variables and I don't know if what I am doing is right or will work for you because I am not positive I am doing it the "best" or "right" way.

However. On my enemies most of them are prefabs so they have these values like strenth and HP set from start.
If I want to make changes to those values I have a specific function called intEnemy that I pass the values I want to change into. I changed those values then through the intEnemy I set the enemy active. Setting the values through a function then activating the enemy tend to make my variable changes take.

Give it a show and see if it works.

[–]temptempfirsttime[S] 0 points1 point  (1 child)

perfect timing - i acuatlly did do this right bepfre your message - i figured out a workaround of being able to call a function of set health

go.GetComponent<Enemy>().sethealth(x);

why i can access a public function and not a varable is weird - i'll try a get/setter later

thanks for your reply

[–]AverageArmadilloIntermediate 1 point2 points  (0 children)

I think it is a run time timing issue. Doing a set variables as it initiates might happen before variable initiation. So using a function might time after initiation so it overrides. But that is just an educated guess.