I’m trying to create a basic array of buildings, and store each Building object in an array slot. The array will hold a list of Building’s that can later be put into a menu that would place the object in the world. If there is a better way to create an array to be accessed, besides a static class, which is storing all of my predetermined buildings, it would be awesome to learn!
Problem: The array of objects I am creating gives a syntax error saying it expects [ ] or ,
[23646-capture.jpg*|23646]
Aside from what I’m trying. This is what I have in mind for the game system I am making. The player opens a menu, picks a building and places a building. The buildings are predetermined and listed onto a
BUILDING OBJECT------------------------------------------------------------
using UnityEngine;
using System.Collections;
public class Building : MonoBehaviour {
private int curHealth;
private int maxHealth;
private bool isAlive;
public Building(int curHealth, int maxHealth, bool isAlive){
this.curHealth=curHealth;
this.maxHealth=maxHealth;
create();
}
public void destroy()
{
this.destroy();
}
public Building create()
{
isAlive=true;
return this;
}
public bool getAlive()
{
return isAlive;
}
public void hpUpdate()
{
if (curHealth<=0)
{
isAlive=false;
destroy ();
}
else{
curHealth+=2;
}
}
}
CLASS THAT STORES BUILDINGS---------------~ERROR IS IN THIS CLASS~----------------
using UnityEngine;
using System.Collections;
public static class BuildingList {
static Building[] buildings=new Building[3];
buildings[0]=new Building(100, 100, true);
buildings[1]=new Building(500, 500, true);
buildings[2]=new Building(50, 100, true);
static public Building[] getList()
{
return buildings;
}
}
MENU TO BUILD------------------------------------
using UnityEngine;
using System.Collections;
public class BuildMenu : MonoBehaviour {
Building[] temp;
// Use this for initialization
void Awake () {
Building[] temp=BuildingList.getList();
}
// Update is called once per frame
void Update () {
if(Input.GetButtonDown("Build"))
{
}
}
void FixedUpdate(){
for(int i=0;i<temp.Length;i++)
{
temp*.hpUpdate();*
-
}*
-
}*
}