void Start() { allTiles = Resources.LoadAll("Game/World/Tiles", typeof(GameObject)); tilesMatrix = GenerateTilesMatrix(); for (int i = 0; i < tilesMatrix.Count; i++) { List <TileData> row = tilesMatrix[i]; for (int j = 0; j < row.Count; j++) { TileData tile = row[j]; Vector3 position = new Vector3(j * 35, 0, i * -35); if (tile != null) { GameObject tileObject = GetTileObjectByName(tile.name); float angle = -90 * tile.rotation; Instantiate(tileObject, position, Quaternion.Euler(0, angle, 0)); } } Rebake(); } GameObject player = SpawnAtRandomPoint(playerPrefab); FollowCamera followCamera = camera.GetComponent <FollowCamera>(); followCamera.target = player.transform; for (int i = 0; i < numberOfEnemies; i++) { SpawnAtRandomPoint(enemyPrefab); } }
void Start() { tilesMatrix = GenerateTilesMatrix(); for (int i = 0; i < tilesMatrix.Count; i++) { List <TileData> row = tilesMatrix[i]; for (int j = 0; j < row.Count; j++) { TileData tile = row[j]; Vector3 position = new Vector3(j * 35, 0, i * -35); if (tile != null) { GameObject tileObject = GetTileObjectByName(tile.name); float angle = -90 * tile.rotation; Instantiate(tileObject, position, Quaternion.Euler(0, angle, 0)); } } Rebake(); } // towerPosition = new Vector3(UnityEngine.Random.Range(0,35f*width), 0, UnityEngine.Random.Range(0, -35f*height)); towerPosition = new Vector3(0, 0, 0); // GameObject towerGameObject = SpawnAtPoint(towerPrefab, towerPosition); // towerPosition = towerGameObject.transform.position; GameObject player = SpawnAtPoint(playerPrefab, towerPosition); FollowCamera followCamera = camera.GetComponent <FollowCamera>(); followCamera.target = player.transform; for (int i = 0; i < numberOfEnemies; i++) { bool pathFound = false; while (!pathFound) { Vector3 randomPosition = new Vector3(UnityEngine.Random.Range(-17.5f, (35f * width - 17.5f)), 0, UnityEngine.Random.Range(17.5f, (-35f * height + 17.5f))); GameObject portalGameObject = SpawnAtPoint(enemyPrefab, randomPosition); NavMeshAgent portalNavMeshAgent = portalGameObject.GetComponent <NavMeshAgent>(); if (!CalculateNewPath(portalNavMeshAgent, towerPosition)) { // Vector3 pos = portalGameObject.transform.position; // int row = (int)Math.Round(pos.z/35); // int column = (int)Math.Round(pos.x/35); // if (tilesMaskMatrix[row][column] == 1) { // tilesMaskMatrix[row][column] = 0; // } Destroy(portalGameObject); } else { pathFound = true; } } } }