private void AddRoomsFloors() { Quaternion up = Quaternion.LookRotation(Vector3.up); // Since we have the info of the rooms lets iterate over each of them foreach (var room in _dungeon.rooms) { GameObject newFloor = (GameObject)Instantiate( _floorPrefab, // Prefab ref new Vector3( // Position room.x + room.width * 0.5f, // Fix possition based on scale 0, room.y + room.height * 0.5f // Fix possition based on scale ), up, // Face up, since its a _floorPrefab transform // Set this object as parent ); // This is to fix the scale on the clients and fix the texture FixScaling fixScale = newFloor.GetComponent <FixScaling>(); fixScale.scale = new Vector3(room.width, room.height, 1f); // Spawn on clients NetworkServer.Spawn(newFloor); // The middle of all rooms are valid spawn points GameObject spawnPoint = new GameObject("SpawnPoint"); spawnPoint.transform.parent = newFloor.transform; spawnPoint.transform.position = newFloor.transform.position; NetworkManager.RegisterStartPosition(spawnPoint.transform); } }
private void CreateWall(ArrayList wall) { // Item 0 and 1 of the array represent start and end of the wall. Vector2 wallStart = (Vector2)wall[0]; Vector2 wallEnd = (Vector2)wall[1]; // Figure out its lenght var wallLength = wallEnd.x - wallStart.x + wallEnd.y - wallStart.y; float x; float y; // Figure out if its horizontal or vertical and set position properly var wallDirection = wallEnd - wallStart; if (wallDirection.x > 0) { x = wallStart.x + wallLength * 0.5f; y = wallStart.y; } else { x = wallStart.x; y = wallStart.y + wallLength * 0.5f; } GameObject newWall = (GameObject)Instantiate( _wallPrefab, // Prefab ref new Vector3( // Position x, 1f, y ), GetWallRotation(wall), transform // Set this object as parent ); // This is to fix the scale on the clients and fix the texture FixScaling fixScale = newWall.GetComponent <FixScaling>(); fixScale.scale = new Vector3(wallLength, 2f, 1f); NetworkServer.Spawn(newWall); }
private void CreateCorridor(ArrayList corridor) { // Item 0 and 1 of the array represent start and end of the corridor. Vector2 corridorStart = (Vector2)corridor[0]; Vector2 corridorEnd = (Vector2)corridor[1]; // Figure out its lenght var corridorLength = corridorEnd.x - corridorStart.x + corridorEnd.y - corridorStart.y; float xScale; float yScale; // Figure out if its horizontal or vertical and set scale properly var corridorDirection = corridorEnd - corridorStart; if (corridorDirection.x > 0) { xScale = corridorLength; yScale = 1f; } else { xScale = 1f; yScale = corridorLength; } GameObject newCorridor = (GameObject)Instantiate( _floorPrefab, // Prefab ref new Vector3( // Position corridorStart.x + xScale * 0.5f, // Fix possition based on scale 0, corridorStart.y + yScale * 0.5f // Fix possition based on scale ), Quaternion.LookRotation(Vector3.up), // Face up, since its a _floorPrefab transform // Set this object as parent ); // This is to fix the scale on the clients and fix the texture FixScaling fixScale = newCorridor.GetComponent <FixScaling>(); fixScale.scale = new Vector3(xScale, yScale, 1f); NetworkServer.Spawn(newCorridor); }