- Home /
Enemy atributes script
Hi there guys!
So, im new to c# scripting, and i want to know how do i create anything similar to an reference script. To be more clear, i want to create an script like :
public class EnemyAtributes:
public EnemyDragonAtributes
{
float enemyHealth = 10f;
float enemy power = 20f;
string enemyName = "Dragon";
}
public EnemyMageAtributes
{
float enemyHealth = 10f;
float enemy power = 20f;
string enemyName = "Mage";
}
and when i need that in code, on another script, ill use something like:
public class GameBaseScript:
void Update()
{
float enemyHP = EnemyAtributes.EnemyDragonAtributes.enemyHealth;
}
Is there any way to do that? Basically is an script to store the information from all my monsters and when i need, ill use them on script, instead of creating lots of variables like "enemyDragonHp,EnemyMageHP,enemyDragonName,EnemyMageName,Enemy..." Sorry for my english, im not too good at it !
Answer by Sessional · May 01, 2015 at 04:48 PM
What you need to do is to make the class that has these stats extend a MonoBehavior and then you can just attach them to said objects. The one thing that this will require is that to get the values inside of a different class you need to have a reference to them (which can be done many ways - simplest is just make a GameObject variable in a class in the script you use it and set that) and use GetComponent().health;
For example:
public class DragonAttributes : MonoBehavior
{
public float health = 10f;
public float enemyPower = 20f;
public string enemyName = "Dragon";
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613194452im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
(C#) Enemy health and take damage from bullets 1 Answer
Distribute terrain in zones 3 Answers
how do i make an Enemy take damage from prefab bullet clone? 1 Answer
Enemy Health GUI Issues 0 Answers