- Home /
Unity2D: Best way to store GameObject attributes
I'm making a small game and I have a script attached to my enemy prefab that controls their actions. I want to add a custom attribute for speed as well as x and y dimensions but I'm unsure of what's the best way of going about this.
Should I just declare them in the enemy script I have and create a reference to the script in other scripts where I need these values or would it be better to create a new script that isn't monobehavior and contains an enemy class with the properties mentioned above that gets a reference initialized for each enemy on the scene?
For example, the enemy controller script will be called EnemyController.cs and the class I am referring to is just named Enemy.cs. Each prefab that's instantiated will have its own EnemyController script that will initialize a reference to the Enemy class (Enemy e = new Enemy(stuff))
Are any of these two methods better than the other and would the latter option save me from having to create references to the EnemyCOntroller script everywhere I need to get or change these values or would it be the same thing? I just want to keep my code as clean and organized as possible.