I have a Spawner
class
that references a list of Scriptable Object
s (enemies).
This list is passed into a function that spawns those enemies.
Once a wave is destroyed, I want to then reference another Scriptable Object
list that has BOSS enemies.
I want to be able to pass this new list into the same function however, the function parameter type is expecting the regular enemy list and not the boss list.
I could simply overload the function and duplicate the code but that is ugly. I’d like a more elegant solution. I was hoping I could pass either enemy type list into the function as they both have the same spawn process.
// paste code here
How can I resolve this?
Thanks dstears. That was a thought. I have a process in the game to where I need all lasers to be off the screen before initiating the bonus sequence. I have a laser type and a bomb type that have different behaviors. OnEnable, I have them referencing themselves than passing themselves into an Ordinance management class. In this class, the function argument I accept a Monobehavior and I can pass either ordanance type into the list. But it seems I can’t do the same with scriptable object lists.
I see. I missed the detail that this was a list of Scriptable Objects. Since it sounds like the Spawner class will work with either the Regular or Boss ScriptableObject, does that mean that it only uses fields that exist in both flavors of ScriptableObject?
You still should be able to create a parent class that derives from ScriptableObject then have the RegularEnemy and Boss classes derive from the parent class.
I mean something like this:
public class ParentEnemy : ScriptableObject
{
public int CommonParameter1;
public int CommonParameter2;
}
public class BossEnemy : ParentEnemy
{
int bossParameter;
}
public class RegularEnemy : ParentEnemy
{
int regularEnemyParameter;
}
public class Spawner : MonoBehaviour
{
public void DoStuff(List<ParentEnemy> myList)
{
int foo = myList[0].CommonParameter1;
int bar = myList[0].CommonParameter2;
}
}