コード例 #1
0
    public override void Move(GameObject target, int distance = 2)
    {
        if (AIAbilities[1].GetRange() > Vector3.Distance(transform.position, target.transform.position) || target == null)
        {
            return;
        }
        List <Node> calculatedPositions = AIAlgorithms.AvailableTiles(target, distance);
        int         randomNumber        = Random.Range(0, calculatedPositions.Count);

        AIAlgorithms.occupiedTiles.Add(calculatedPositions[randomNumber]);
        this.gameObject.GetComponent <Unit>().GeneratePathTo(calculatedPositions[randomNumber].x, calculatedPositions[randomNumber].y);
        print(this.gameObject + " is moving towards " + target);
    }
コード例 #2
0
    public override void Move(int distance = 2)
    {
        List <Node> calculatedPositions;
        int         randomNumber;

        List <GameObject> teamOne = GameManager.teamTwo;

        foreach (GameObject target in teamOne)
        {
            if (target.GetComponent <Unit>().UnitHealthState == Unit.HealthState.low)
            {
                healTarget = target;
                if (GetComponent <Heal>().GetRange() > Vector3.Distance(transform.position, target.transform.position))
                {
                    return;
                }
                calculatedPositions = AIAlgorithms.AvailableTiles(target, distance);
                randomNumber        = Random.Range(0, calculatedPositions.Count);
                AIAlgorithms.occupiedTiles.Add(calculatedPositions[randomNumber]);
                this.gameObject.GetComponent <Unit>().GeneratePathTo(calculatedPositions[randomNumber].x, calculatedPositions[randomNumber].y);
                return;
            }
            if (target.GetComponent <Unit>().UnitHealthState == Unit.HealthState.damaged)
            {
                healTarget = target;
                if (GetComponent <Heal>().GetRange() > Vector3.Distance(transform.position, target.transform.position))
                {
                    return;
                }
                calculatedPositions = AIAlgorithms.AvailableTiles(target, distance);
                randomNumber        = Random.Range(0, calculatedPositions.Count);
                AIAlgorithms.occupiedTiles.Add(calculatedPositions[randomNumber]);
                this.gameObject.GetComponent <Unit>().GeneratePathTo(calculatedPositions[randomNumber].x, calculatedPositions[randomNumber].y);
                return;
            }
        }

        teamOne      = GameManager.teamOne;
        randomNumber = Random.Range(0, teamOne.Count);
        GameObject followingTarget = teamOne[randomNumber];

        if (AIAbilities[1].GetRange() > Vector3.Distance(transform.position, followingTarget.transform.position))
        {
            return;
        }
        calculatedPositions = AIAlgorithms.AvailableTiles(followingTarget, distance);
        randomNumber        = Random.Range(0, calculatedPositions.Count);
        AIAlgorithms.occupiedTiles.Add(calculatedPositions[randomNumber]);
        this.gameObject.GetComponent <Unit>().GeneratePathTo(calculatedPositions[randomNumber].x, calculatedPositions[randomNumber].y);
    }
コード例 #3
0
    public override void Move(int distance = 2)
    {
        List <GameObject> teamOne = GameManager.teamOne;
        int        randomNumber   = Random.Range(0, teamOne.Count);
        GameObject target         = teamOne[randomNumber];

        if (AIAbilities[1].GetRange() > Vector3.Distance(transform.position, target.transform.position))
        {
            return;
        }
        List <Node> calculatedPositions = AIAlgorithms.AvailableTiles(target, distance);

        randomNumber = Random.Range(0, calculatedPositions.Count);
        AIAlgorithms.occupiedTiles.Add(calculatedPositions[randomNumber]);
        this.gameObject.GetComponent <Unit>().GeneratePathTo(calculatedPositions[randomNumber].x, calculatedPositions[randomNumber].y);
    }