I’m woking on some kind of Tower Defence Game, and I need level configuration.
When I work’d on AS3 projects I used xml files to config game play fetures. What the best way in unity to do this?
Also I have some quastions about stage initialize. For now I’m doing it like this:
I have some bots and turels, thay initializing on Start
Example:
void Start () {
type = Type.BOT;
walker = GetComponent(typeof(BotWalker)) as BotWalker;
fightController = GetComponent(typeof(ShootController)) as ShootController;
animController = GetComponent(typeof(BotAnimationsController)) as BotAnimationsController;
gameObject.tag = Tag.ENEMY;
if(autoRegister) {
Main.register(gameObject, type);
Invoke("activate", 0.5f);
}
}
I need to activate tham only after all objects are registren in controllers.
Here is Controller object registration:
void Awake () {
object[] obj = GameObject.FindSceneObjectsOfType(typeof (GameObject));
foreach (object o in obj) {
GameObject g = (GameObject) o;
if(g.GetComponent(typeof(FenceAI)) != null) {
fences.Add(g);
}
if(g.GetComponent(typeof(HouseAI)) != null) {
houses.Add(g);
}
if(g.GetComponent(typeof(BotAI)) != null) {
bots.Add(g);
}
if(g.GetComponent(typeof(TurelAI)) != null) {
turels.Add(g);
}
if(g.GetComponent(typeof(SpawnGateAI)) != null) {
gates.Add(g);
}
}
Debug.Log(fences.Count + " Fenses registerd so far");
Debug.Log(houses.Count + " Houses registerd so far");
Debug.Log(bots.Count + " Bots registerd so far");
Debug.Log(turels.Count + " Turels registerd so far");
Debug.Log(gates.Count + " Gates registerd so far");
}
I can be shure thal all of that done (Awake for controller / Start for objects) only in controller Update function, so I do that:
void Update() {
if(!gameStarted) {
awakeBots();
awakeTurels();
gameStarted = true;
}
}
I have strong feeling that, this is not the best way… Will be presheated for some help