Answer the question
In order to leave comments, you need to log in
How should the logic and syntax of passing data to another class work?
The essence is simple, in one class there is an array with data about opponents, then there is an enemy behavior class where this array should be connected and actually give each opponent the necessary properties based on the data from the array ...
I still don’t understand how to do this.
Based on PHP knowledge, the array should look like this
$arr_enemy=array(
'enemy_1'=array(
'name'=>'enemy 1',
'life'=>100
),
'enemy_2'=array(
'name'=>'enemy 2',
'life'=>50
)
);
public class EnemyData : MonoBehaviour{
Dictionary<string,string> ArrayEnemyData = new Dictionary<string,string>
{
["EnemyName"] = "Enemy 1",
//["EnemyLife"] = 100,
};
}
public class Enemy : MonoBehaviour{
arr = EnemyData.ArrayEnemyData;
}
Answer the question
In order to leave comments, you need to log in
Use string ("enemy_1" etc.) as a key, and the Enemy
(Dictionary) class as a value.
You get something like:
var name = enemies["enemy_1"].Name;
var life = enemies["enemy_1"].Life;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question