本文整理汇总了C#中IGameObject.StopAttack方法的典型用法代码示例。如果您正苦于以下问题:C# IGameObject.StopAttack方法的具体用法?C# IGameObject.StopAttack怎么用?C# IGameObject.StopAttack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGameObject
的用法示例。
在下文中一共展示了IGameObject.StopAttack方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryAttack
/// <summary>
/// Checks if gameObject can attack the target.
/// </summary>
/// <param name="gameObject">The attacking object the target.</param>
/// <param name="target">The target of the attack.</param>
/// <param name="attackDistance">The maximum distance between the objects for attack.</param>
/// <returns>Returns if attacker can attack the target.</returns>
public bool TryAttack(IGameObject gameObject, IGameObject target, float attackDistance)
{
// Checks if object is freezed.
if (CanAttack(gameObject)) {
var xd = target.Position.x - gameObject.Position.x;
var yd = target.Position.z - gameObject.Position.z;
var squareDistance = xd * xd + yd * yd;
if (squareDistance > attackDistance * attackDistance) {
// Cannot attack because it is too far.
var imgo = gameObject as IMovableGameObject;
if (imgo != null) {
gameObject.StopAttack();
if (!movingDict.ContainsKey(imgo)) {
movingDict.Add(imgo, target);
}
// Move attacker closer to target.
Game.IMoveManager.GoToTarget(imgo, target, this);
}
return false;
}
return true;
}
return false;
}