Best Way to Using Same Variables Between 2 Scripts

Hi I have a Enemy.cs and Snake.cs

Enemy.cs have MaxHp,CurrentHp,Attack Damage

These are going to be same for every enemy

I don’t want write these over and over to Snake.cs
I know i can use like Attack() for between two scripts
But can i use “public float maxHealth” between 2 scripts

And which way should i use ?

Scriptable objects,interfaces,abstract classes
Which one is good ?

Well, a couple options. First is just a base class that you inherit from. Second way would be to have a script with all the stats on it and just include a reference to that script. So you would have EnemyStats and Snake.cs on a gameobject. And Snake.cs would reference EnemyStats.cs which would just hold it’s MaxHp, currenthp, etc.

1 Like