edited March 2015 in ORK Scripting
I have a working battle with one enemy in my scene. To access the battle component I do:


public GameObject battleObject1;
BattleComponent battleComponent1;

void Start()
{
battleComponent1 = battleObject1.GetComponent();
}

and I want to change the enemy via script. I think this should work by

battleComponent1.combatant[0] = SOMETHING

but I'm missing the SOMETHING part.

I've tried to set up a combatant like in the script tutorial but I get a "Cannot implicitly convert type 'ORKFramework.Combatant' to 'ORKFramework.BattleCombatant'" error:


public class ChangeEnemy : MonoBehaviour
{
public GameObject battleObject1;
BattleComponent battleComponent1;
Group group = new Group(1);
Combatant combatant;


void Start()
{
battleComponent1 = battleObject1.GetComponent();
combatant = ORK.Combatants.Create(3, group);
combatant.Init();
}

public void Change()
{
battleComponent1.combatant[0] = combatant;
}
}


EDIT:
It doesn't have to be a newly spawned combatant, either - I'd be perfectly fine with simply picking (and maybe adjusting) one from the already existing list I set up in the ORK editor.
Post edited by UmalasAmbon on
  • The combatant field in the Battle component isn't a Combatant (which is an actual combatant, holding stats, etc.), but only the setup for creating the combatant (i.e. a BattleCombatant class).
    It only holds the id, faction, etc of the combatant and will use that info when the battle is started to create the combatants.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • So how do I change which combatant will be used once the battle is started then? Am I at least on the right track with BattleComponent?
  • Yes, just create a new instance of BattleCombatant and set it up to your needs.

    See the API for the different fields. The id field is the ID of the combatant group that will be used. When you want a single combatant to be used, set up the member field with a new CombatantGroupMember instance.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Setting it up to change the group was surprisingly easy, thanks for holding my hand, lol.
    I'm stuck again with the CombatantGroupMember stuff but luckily I can just make groups with only one member and call them, which works for my purposes, for now.

    For future reference:

    public GameObject battleObject1;
    BattleComponent battleComponent1;
    BattleCombatant newBattleCombatant;



    void Start()
    {
    battleComponent1 = battleObject1.GetComponent();
    newBattleCombatant = new BattleCombatant();
    newBattleCombatant.id = 2;
    newBattleCombatant.factionID = 1;
    }

    public void Change()
    {
    battleComponent1.combatant[0] = newBattleCombatant;
    }
    }
Sign In or Register to comment.