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); }
//destroy a single asset public void DestroyAsset(GameObject asset) { if (PlacedAssets.Contains(asset)) { PlacedAssets.Remove(asset); Destroy(asset); } }