private Color hearingColor = Color.red;                     //Color for hearing sphere gizmo, init. red.



    // Start is called before the first frame update
    void Start()
    {
        //Get and set data and motor on Start
        data    = GetComponent <TankData>();
        motor   = GetComponent <TankMotor>();
        tf      = GetComponent <Transform>();
        shooter = GetComponent <TankShooter>();

        //get reference to manager player (temporary until next milestone)
        player = GameManager.instance.instantiatedPlayerTank;

        //Add self to GameManager list of enemies
        GameManager.instance.instantiatedEnemyTanks.Add(this.gameObject);

        //Get and Set Territory from randomly generated room, if not pre-set
        if (!territory)
        {
            //Set Territory to a random territory from the level game object - map generator list of territories
            territory = GameManager.instance.LevelGameObject.GetComponent <MapGenerator>().instantiatedTerritories[UnityEngine.Random.Range(0, GameManager.instance.LevelGameObject.GetComponent <MapGenerator>().instantiatedTerritories.Count)];
        }

        //Get and Set Waypoints array from territory, if waypoints array is null
        if (waypoints == null || waypoints.Length == 0)
        {
            waypoints = territory.waypoints;
        }

        //Teleport Swiss on start to middle of assigned territory (to avoid getting lost and stuck in generated map
        if (personality == Personalities.Swiss)
        {
            transform.position = territory.gameObject.transform.position;
        }
    }
Exemplo n.º 2
0
    //Randomly generate the grid for the level
    public void GenerateGrid()
    {
        UnityEngine.Random.seed = mapSeed;

        grid = new Room[MapCols, MapRows];

        //for each row
        for (int row = 0; row < MapRows; row++)
        {
            //for each column in row
            for (int col = 0; col < MapCols; col++)
            {
                float xPosition = roomWidth * col;
                float zPosition = roomLength * row;

                Vector3 newPosition = new Vector3(xPosition, 0.0f, zPosition);

                //Instantiate random room at position at prefab rotation
                GameObject tempRoomObj = Instantiate(GetRandomRoom(), newPosition, Quaternion.identity) as GameObject;

                //If Room has a territory child on it, add to list of territories
                RoomTerritory roomTerritory = tempRoomObj.GetComponentInChildren <RoomTerritory>();
                if (roomTerritory)
                {
                    instantiatedTerritories.Add(roomTerritory);
                }

                //Set our room's parent object
                tempRoomObj.transform.parent = this.transform;

                //Rename our room object as Room_x,y
                tempRoomObj.name = "Room_" + col + "," + row;

                //Store room in 2d array of grid
                Room tempRoom = tempRoomObj.GetComponent <Room>();
                grid[col, row] = tempRoom;

                //If room is at bottom of grid, open North door
                if (row == 0)
                {
                    tempRoom.doorNorth.SetActive(false);
                }

                //If room is at top of grid, open the south door
                else if (row == MapRows - 1)
                {
                    tempRoom.doorSouth.SetActive(false);
                }

                //Else is in the middle, open South and North Doors
                else
                {
                    tempRoom.doorSouth.SetActive(false);
                    tempRoom.doorNorth.SetActive(false);
                }

                if (col == 0)
                {
                    tempRoom.doorEast.SetActive(false);
                }

                else if (col == MapCols - 1)
                {
                    tempRoom.doorWest.SetActive(false);
                }

                else
                {
                    tempRoom.doorEast.SetActive(false);
                    tempRoom.doorWest.SetActive(false);
                }
            }
        }
    }