// Use this for initialization void Start() { pHealth = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerHealth>(); meshRenderer = GetComponent <MeshRenderer>(); tileStuff = GetComponent <TileStuff>(); boxColl = GetComponent <BoxCollider>(); }
void floodFillStep() { while (q.Count > 0) { IntVector2 n = q.Dequeue(); if (map[n.x, n.y].tileType != target) { continue; } //switch tile Destroy(map[n.x, n.y].tile); GameObject tile = map[n.x, n.y].gameObject; // GameObject tileDesign = (GameObject)Instantiate(HexTilePrefab[replacement], Vector3.zero, Quaternion.identity); tileDesign.transform.parent = tile.transform; tileDesign.transform.localPosition = Vector3.zero; TileStuff tileStuff = tileDesign.GetComponent <TileStuff>(); if (map[n.x, n.y].doStuff) { tileStuff.refresh(); } // map[n.x, n.y].tileType = replacement; map[n.x, n.y].tile = tileDesign; //add neighbors to queue if (n.y % 2 == 1) { //Debug.Log (" y % 2 == 1 "+n.x+" "+n.y ); addNeighber(q, n.x, n.y - 1); addNeighber(q, n.x - 1, n.y); addNeighber(q, n.x, n.y + 1); addNeighber(q, n.x + 1, n.y + 1); addNeighber(q, n.x + 1, n.y); addNeighber(q, n.x + 1, n.y - 1); //addNeighber(q, n.x-1,n.y+1); } else { //Debug.Log (" y % 2 == 0 "+n.x+" "+n.y ); addNeighber(q, n.x - 1, n.y - 1); addNeighber(q, n.x - 1, n.y); //addNeighber(q, n.x+1,n.y-1); addNeighber(q, n.x - 1, n.y + 1); addNeighber(q, n.x, n.y + 1); addNeighber(q, n.x + 1, n.y); addNeighber(q, n.x, n.y - 1); } return; } }
public void GenerateGrid() { float inradius = (float)(0.5 * Mathf.Sqrt(3) * HexSideLength); float spaceBetweenTilesHorizontal = 2.0f * inradius; float spaceBetweenTilesVertical = 1.5f * HexSideLength - 0.15f; map = new Tile[Width, Height]; if (HexTilePrefab != null) { for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { GameObject tile = (GameObject)Instantiate(TilePrefab, Vector3.zero, Quaternion.identity); tile.transform.parent = gameObject.transform; //+ Random.Range(0.0f,0.5f) tile.transform.localPosition = new Vector3(x * spaceBetweenTilesHorizontal + (y & 1) * inradius, y * spaceBetweenTilesVertical, y); // int random = Random.Range(0, numberOfChoices); GameObject tileDesign = (GameObject)Instantiate(HexTilePrefab[random], Vector3.zero, Quaternion.identity); tileDesign.transform.parent = tile.transform; tileDesign.transform.localPosition = Vector3.zero; // TileStuff tileStuff = tileDesign.GetComponent <TileStuff>(); tileStuff.refresh(); // map[x, y] = tile.GetComponent <Tile>(); map[x, y].tileType = random; map[x, y].tile = tileDesign; map[x, y].x = x; map[x, y].y = y; } } } // Center the Grid gameObject.transform.Translate(new Vector3(-spaceBetweenTilesHorizontal * Width / 2.0f + inradius + 1.0f, -spaceBetweenTilesVertical * Height / 2.0f - HexSideLength + 0.5f, 0)); }
static void Main(string[] args) { GameObject[] arr = new GameObject[2]; arr[0] = new TileStuff(); arr[1] = new MoreTileStuff(); }