Attack Order

public sealed class AttackOrder : Order

This class is used for attack orders for a unit. It contains an AttackTarget field, which stores the target for the unit’s attack.

Example

// this example code running from Unit.cs component

Unit unit = this; // getting the unit component from which we run this code.
Unit enemyUnit = FindAnyObjectByType<Unit>(); // suppose that here we are setting up the Unit component of another unit.

AttackOrder order = new AttackOrder(enemyUnit); // creating new AttackOrder here, with the enemy unit as its attack target.

unit.AI.AddOrder(order, false); // adding the created order to the unit's orders list. Now the unit will attack the enemy unit.