Last active
August 29, 2015 13:55
-
-
Save wmiller/8779053 to your computer and use it in GitHub Desktop.
XML Database Example1 MapBuilder1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class MapBuilder1 : MapBuilder | |
{ | |
public int FeatureChance = 30; | |
public string[] TileLoadStrings; | |
public string[] FeatureLoadStrings; | |
protected override void InitMapObjects() | |
{ | |
for (int y = 0; y < Height; ++y) | |
{ | |
for (int x = 0; x < Width; ++x) | |
{ | |
int height = HeightField[y * Width + x]; | |
// Create tile | |
if (height >= 0 && height < TileLoadStrings.Length) | |
{ | |
GameObject prefab = Resources.Load<GameObject>(TileLoadStrings[height]); | |
InstantiateMapPrefab(x, y, MapObjectDepth.Tile, prefab); | |
} | |
// Randomly create a feature for this tile (not on water) | |
if (height > 0 && Random.Range(0, 100) < FeatureChance) | |
{ | |
string randomFeaturePath = FeatureLoadStrings[Random.Range(0, FeatureLoadStrings.Length)]; | |
GameObject prefab = Resources.Load<GameObject>(randomFeaturePath); | |
InstantiateMapPrefab(x, y, MapObjectDepth.Feature, prefab); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment