Пример #1
0
    GameObject SelectTarget()
    {
        GameObject newTarget = null;
        float minDistance = float.MaxValue;

        foreach (GameObject roach in roaches)
        {
            if (roach != null)
            {
                float distance = (roach.transform.position - gameObject.transform.position).magnitude;
                if (distance <= maxAttackDistance && distance >= minAttackDistance && distance < minDistance)
                {
                    newTarget = roach;
                    minDistance = distance;
                    curTargetParametrs = newTarget.GetComponent<RoachAI>();
                }
            }
        }

        return newTarget;
    }
Пример #2
0
    void SpawnRoach()
    {
        // Update A* path to the current maze
        AstarPath.active.Scan();

        // Spawn roach
        Transform roachCell     = MazeGenerator.instance.GetCells()[Random.Range(0, MazeGenerator.instance.GetCells().Count)];
        Vector3   roachPosition = new Vector3(roachCell.position.x, 1.5f, roachCell.position.z);

        // Make sure the roach won't spawn too close to the player
        while (Vector3.Distance(player.transform.position, roachPosition) < 70)
        {
            roachCell     = MazeGenerator.instance.GetCells()[Random.Range(0, MazeGenerator.instance.GetCells().Count)];
            roachPosition = new Vector3(roachCell.position.x, 1.5f, roachCell.position.z);
        }

        roach      = Instantiate(roachPrefab, roachPosition, Quaternion.identity);
        roach.name = "Roach";

        RoachAI ai = roach.GetComponent <RoachAI>();

        ai.player = player.transform;
    }
Пример #3
0
 // Use this for initialization
 void Start()
 {
     targetParametrs = target.GetComponent<RoachAI>();
     gameObject.transform.up = parent.transform.up;
 }