Unit
namespace Griff.Modules.Strategy;
public sealed class Unit : Component, ITeamMemberSomething a team can select and order about with no code: click it (or drag a box round it) and right-click where it should go or what it should attack. It walks around buildings, rocks and walls on its own, and units stand apart rather than on top of each other. Give it a Health to be hurt, a Fighter to fight, and a Worker to gather and build.
A unit made by a Producer is a prefab; its Cost, TrainTime, Supply and Hotkey say what training it takes. Scripts can order it about with MoveTo, AttackMoveTo, Attack, Stop and Hold.
This is a component: its saved properties are on its component page.
Properties
Section titled “Properties”public string? Cost { get; set; }What training it costs, e.g. “50 Gold” or “60 Gold, 20 Wood”.
Destination
Section titled “Destination”public Vector2 Destination { get; }Where it’s headed, for Move and AttackMove.
Hotkey
Section titled “Hotkey”public string? Hotkey { get; set; }The key that trains it from a building, e.g. “W”. Empty uses its first letter.
IsSelected
Section titled “IsSelected”public bool IsSelected { get; }True while the player has it selected.
public UnitOrder Order { get; }What it’s doing now.
Radius
Section titled “Radius”public float Radius { get; set; }How much room it takes up: for clicking it, its selection ring, and keeping others off it.
public float Sight { get; set; }How far it sees through the fog of war, and how close an enemy has to come for it to notice.
public float Speed { get; set; }World units per second.
Supply
Section titled “Supply”public int Supply { get; set; }The supply it takes up. A team can only have as much as its buildings provide.
Target
Section titled “Target”public Entity? Target { get; }What it’s attacking, gathering from or building, if anything.
public string? Team { get; set; }The team it’s on: a Faction’s Team, e.g. “Player” or “Enemy”.
TrainTime
Section titled “TrainTime”public float TrainTime { get; set; }Seconds a Producer takes to train it.
Methods
Section titled “Methods”Attack
Section titled “Attack”public void Attack(Entity target)Goes after target until it’s gone.
AttackMoveTo
Section titled “AttackMoveTo”public void AttackMoveTo(Vector2 position)Walks to position, fighting whatever it meets on the way.
public void Hold()Stands its ground, fighting only what comes within reach.
MoveTo
Section titled “MoveTo”public void MoveTo(Vector2 position)Walks to position, ignoring enemies on the way.
public void Stop()Stops whatever it’s doing.
Events
Section titled “Events”Arrived
Section titled “Arrived”public event Action<Unit>? ArrivedRaised when it gets where it was told to go.