Hello, i have a question about prefabs hierarchy. On the scene i have many different kind of enemies. Each Enemy can use the same weapon as player but with different variable (projectile speed, damage etc). My question is about the best way organize this, can i use different prefab weapon per enemy or use one weapon prefab and change value on runtime (read from test assets or similar way). How do you think ??
Thank you very much for your help.
What I do in such case is that my prefabs only contains the structure of an object: textures, meshes, scripts. Then I have two possibilities: I can duplicate the prefabs and modify the scripts values for each configuration I need. Or I can use the second solution (explained later). The main drawback with this method is if I need later to modify the structure I must change all duplicated prefabs as well.
The second method is to use separate assets which contains the variables. And only variables. I do that by extending ScriptableObject:
[System.Serializable]
public class EnemyData : ScriptableObject
{
public int weaponType;
public float weaponDamage;
// etc.
}
My Enemy script will look like:
public class Enemy : MonoBehaviour
{
public EnemyData data;
// code
}
Those assets are inside a Resources folder. So that they are accessible at runtime. I can easily switch one data for another, assign randomly a data, etc.
Ok so choose good way One more really thanks