Usage of RTS Kit features modules in your custom ones
If you’ve inherited your custom module from BaseUnitModule/UnitLogicModule, as shown in the previous section, you can get access to other modules via the Unit component — it contains methods to get any other module, if it’s added to the unit:
using UnityEngine;
using InsaneSystems.RTSKit.Gameplay;
public class CustomModule : BaseUnitModule
{
[Inject] DamageablesService damageables;
public override void Start()
{
if (SelfUnit.TryGetModule<Damageable>(out var damageable))
damageables.ApplyDamage(damageable, 25, Globals.DefaultDamageType); // will damage the unit by 25 damage points.
if (SelfUnit.TryGetModule<IAttack>(out var attack))
Debug.Log(attack.AttackTarget); // will print the attack target of the Attack module, if the unit has it.
// etc, check API Reference for more info
}
}
You can use the TryGetModule() method if you are not sure that it exists on a unit object.
To send a new order to a unit, use the SelfUnit.AI.AddOrder() method. You can send move, follow and attack orders:
var moveOrder = new MovePositionOrder(new Vector3(32, 0, 32));
SelfUnit.AI.AddOrder(moveOrder, false);