public void Generate() { UnityEngine.Random.InitState(Seed); //pick a random position for the feature(s) var position = this.Generator.GetRandomPointInChunk(); float sampleheight = ParentChunk.Terrain.terrainData.GetHeight(position.X, position.Z); Vector3 worldPosition = new Vector3( (ChunkCoords.X * TerrainChunkSettings.ChunkSize) + position.X, sampleheight - 0.5f, (ChunkCoords.Z * TerrainChunkSettings.ChunkSize) + position.Z ); var randomRotation = Quaternion.Euler(0, UnityEngine.Random.Range(0, 360), 0); GameObject dungeontower = (GameObject)Resources.Load("DungeonTower"); var spawntower = Instantiate(dungeontower, worldPosition, randomRotation); Generator.FeatureAssets.Add( spawntower ); //setting the seed for the dungeon in the tower we just placed DungeonEntranceTrigger enterancetrigger = spawntower.gameObject.transform.GetComponentInChildren <DungeonEntranceTrigger>(); enterancetrigger.Seed = ChunkCoords.X * ChunkCoords.Z + 123456; //raycasting the tower to the ground level float distanceToGround = TerrainUtils.RaycastToTerrain(spawntower.transform.position); var pos = spawntower.transform.position; pos = new Vector3(pos.x, (pos.y + distanceToGround), pos.z); spawntower.transform.position = pos; spawntower.transform.SetParent(this.transform); RemoveOverlappingAssets(); }
public void Generate() { UnityEngine.Random.InitState(Seed); //pick a random position for the feature(s) var position = this.FeatureGenerator.GetRandomPointInChunk(); float sampleheight = ParentChunk.Terrain.terrainData.GetHeight(position.X, position.Z); //set the offset for placing in the chunks world position X, Z. uses terrain height for Y Vector3 offsetPosition = new Vector3( (ParentChunk.Position.X * ParentChunk.Terrain.terrainData.size.x) + position.X, ParentChunk.Terrain.terrainData.GetHeight(position.X, position.Z), (ParentChunk.Position.Z * ParentChunk.Terrain.terrainData.size.z) + position.Z ); Quaternion randomRotation = Quaternion.Euler(0, UnityEngine.Random.Range(0, 360), 0); GameObject asset = ChooseRandomAsset(); GameObject spawnedAsset = Instantiate(asset, offsetPosition, randomRotation); PlacedAssets.Add(spawnedAsset); spawnedAsset.transform.parent = ParentChunk.FeatureComponent.transform; //setting the seed for the dungeon in the tower we just placed DungeonEntranceTrigger enterancetrigger = spawnedAsset.gameObject.transform.GetComponentInChildren <DungeonEntranceTrigger>(); enterancetrigger.Seed = ParentChunk.Position.X * ParentChunk.Position.Z + 123456; RemoveOverlappingAssets(spawnedAsset); }