Using RTS Kit events
RTS Starter Kit code contains a lot of events which you can connect your code to. This greatly simplifies the development of new features.
For example, you can do something when any unit is spawned. You can receive info about the spawn by connecting to Unit.UnitSpawned.
using UnityEngine;
using InsaneSystems.RTSKit.Gameplay;
class EventsExample : IInitSystem, IDisposable
{
[Inject] UnitsService units;
public void Init()
{
units.UnitReady += OnUnitReady; // connecting to the UnitReady event. Now, every time any unit is spawned, the attached method will be called.
}
public void Dispose()
{
units.UnitReady -= OnUnitReady; // do not forget to always unsubscribe from events
}
void OnUnitReady(Unit unit)
{
Debug.Log($"Spawned a new unit {unit.name}!"); // this message will appear in console on unit spawn
// your actions here
}
}
The full list of events can be found in the API Reference partition.