Skip to content

Unit

namespace Griff.Modules.Strategy;
public sealed class Unit : Component, ITeamMember

Something 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.

public string? Cost { get; set; }

What training it costs, e.g. “50 Gold” or “60 Gold, 20 Wood”.

public Vector2 Destination { get; }

Where it’s headed, for Move and AttackMove.

public string? Hotkey { get; set; }

The key that trains it from a building, e.g. “W”. Empty uses its first letter.

public bool IsSelected { get; }

True while the player has it selected.

public UnitOrder Order { get; }

What it’s doing now.

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.

public int Supply { get; set; }

The supply it takes up. A team can only have as much as its buildings provide.

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”.

public float TrainTime { get; set; }

Seconds a Producer takes to train it.

public void Attack(Entity target)

Goes after target until it’s gone.

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.

public void MoveTo(Vector2 position)

Walks to position, ignoring enemies on the way.

public void Stop()

Stops whatever it’s doing.

public event Action<Unit>? Arrived

Raised when it gets where it was told to go.