// Start is called on the frame when a script is enabled just before any of the Update methods are called the first time.
 private void Start()
 {
     // Set player in spawn point
     Room.Cell spawnPoint = roomArray[0].GetCellByType(Room.CellType.Spawn_Point);
     if (spawnPoint != null)
     {
         Vector3 position = spawnPoint.getGameObject().transform.position;
         Instantiate(playerPrefab, position, Quaternion.identity);
         cameraPrefab = Instantiate(cameraPrefab, new Vector3(), Quaternion.identity);
     }
 }
    // Awake is called when the script instance is being loaded.
    private void Awake()
    {
        roomWidth        = 10;
        roomHeight       = 8;
        roomArray        = new Room.Grid <Cell> [numRooms];
        roomTemplates    = new List <int[, ]>();
        numTemplateRooms = 16;

        // Create the rooms templates
        for (int i = 0; i < numTemplateRooms; i++)
        {
            buildTemplateRoom(i);
        }

        roomXShift = roomWidth * cellSize;
        int     randomIndex  = 0;
        int     lastIndex    = 0;
        Vector3 roomPosition = new Vector3();

        for (int i = 0; i < numRooms; i++)
        {
            room = new Room.Grid <Cell>(roomWidth, roomHeight, cellSize, tilePalletName, i);

            randomIndex = Random.Range(0, roomTemplates.Count);
            while (randomIndex == lastIndex)
            {
                randomIndex = Random.Range(0, roomTemplates.Count);
            }
            //build a room based on a randomly chosen template.
            room.buildRoom(roomTemplates[randomIndex], roomPosition);
            roomArray[i] = room;

            genEnemies(roomPosition, i, roomArray.Length); //generate enemies on the current room w/ difficulty i out of total rooms
            genBackground(roomPosition);                   //generate background elements on the current room

            // After building the room shift the position of the next room by the room width multiplied by the cell size.
            roomPosition += new Vector3(roomXShift, 0, 0);
            lastIndex     = randomIndex;
        }

        Room.Cell finishPoint = roomArray[numRooms - 1].GetCellByType(Room.CellType.End_Point);
        if (finishPoint != null)
        {
            Sprite sprite = Resources.Load <Sprite>("sign");
            finishPoint.createFinishLine(sprite);
        }
    }