本文整理汇总了C#中GameEntity.GetStateMachine方法的典型用法代码示例。如果您正苦于以下问题:C# GameEntity.GetStateMachine方法的具体用法?C# GameEntity.GetStateMachine怎么用?C# GameEntity.GetStateMachine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameEntity
的用法示例。
在下文中一共展示了GameEntity.GetStateMachine方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateState
public override void UpdateState(GameEntity unit)
{
base.UpdateState(unit);
if (_unitToAttack == null || _unitToAttack.IsDead())
{
unit.GetStateMachine().ChangeState(new RestState());
return;
}
Vector3 unitToAttackPos = _unitToAttack.GetPos();
// As the unit must move towards a dynamic position.
unit.MoveTo(unitToAttackPos);
float extra = _unitToAttack is GameBuilding ? GameBuilding.EXTRA_ATTACK_DIST : 0.0f;
float attackRange = unit.GetAttackRange() + extra;
// Is the unit within attacking distance of the unit to attack?
float distance = Vector3.Distance(unitToAttackPos, unit.GetPos());
if (distance < (attackRange - ARRIVE_THRESHOLD))
{
// Start attacking the other object.
unit.GetStateMachine().ChangeState(new AttackState(_unitToAttack));
}
}