My first question is how can I create a new FactionManager GameObject from a script? I saw on an older thread (viewtopic.php?f=5&t=724) that you recommended doing something like this:
Code: Select all
// Create FactionManager:
var factionManager = new GameObject("LoveHate").AddComponent<FactionManager>();
factionManager.factionDatabase = myDatabase;
My second question is what's the best way to do the same thing for FactionMembers? My project has a lot of procedural characters and I was hoping to just be able to create new factions for them and add them to the database at runtime.
From that same thread I saw an example of creating them: (although I think I'll be instantiating a prefab with the base character components and then either adding a FactionMember component or updating the existing component on the prefab)
Code: Select all
foreach (var character in myCharacters)
{
var characterGO = new GameObject(character.factionName);
characterGO.transform.SetParent(factionManager.transform);
character.factionMember = characterGO.AddComponent<FactionMember>();
character.factionMember.factionID = factionManager.GetFactionID(character.factionName);
// Add other components:
characterGO.AddComponent<StabilizePAD>();
characterGO.AddComponent<EmotionalState>(); //etc.
}
Thanks!