I need to create a list of enemies but didn’t want to make it in the monobehaviour derived class witch is attached to the enemy because I just need one class(list) for the whole game.
So I created a scriptable object and created the list there. Now I need to add in this list the game object that was instantiated (or delete if it was destroied). Although I’m having a hard time to make this reference thing Works. Here is the example:
public class EnemyStateController : MonoBehaviour
{
public ListOfActiveEnemiesObj enemyListInstance;
private void Awake()
{
ListOfActiveEnemiesObj enemyListInstance = ScriptableObject.CreateInstance(typeof(ListOfActiveEnemiesObj)) as ListOfActiveEnemiesObj;
}
private void Start()
{
enemyListInstance.addToList(this);
}
}
public class ListOfActiveEnemiesObj : ScriptableObject
{
public List<GameObject> enemyList;
public void addToList(EnemyStateController enemy)
{
enemyList.Add(enemy.gameObject);
Debug.Log(enemyList);
}
}
So basically I need to connect both classes so I can call the function addToList()