Beispiel #1
0
    public bool Attack(SquadControl targetSquad, bool usePrimary)
    {
        if (!CanAttack)
        {
            Debug.Log(transform.name + " has no way to attack");
            return(false);
        }

        Transform mySquad         = unitControl.Squad.transform;
        Vector3   offsetFromSquad = targetSquad.transform.position - mySquad.position;

        float heading = Vector3.Angle(offsetFromSquad.normalized, mySquad.forward) *
                        Mathf.Sign(Vector3.Dot(offsetFromSquad.normalized, mySquad.right));

        int attackDir = Mathf.RoundToInt(heading / 90);

        bool attackAttempted = false;

        if (offsetFromSquad.magnitude < (GameManager.instance.GridSize * 1.1f))
        {
            attackAttempted = TryMeleeAttack(usePrimary ? primaryWeapon : secondaryWeapon, targetSquad, attackDir);
        }

        if (!attackAttempted)
        {
            attackAttempted = TryAttackRanged(usePrimary ? primaryWeapon: secondaryWeapon, targetSquad, attackDir);
        }

        if (!attackAttempted)
        {
            unitControl.AttackComplete();
        }
        return(attackAttempted);
    }