void UpdatePosition(GridObject tempGrid, int x, int y) { tempGrid.yPos += y; tempGrid.xPos += x; if (tempGrid.yPos == gridSize) { tempGrid.yPos = gridSize - 1; } if (tempGrid.xPos == gridSize) { tempGrid.xPos = gridSize - 1; } if (tempGrid.yPos == -1) { tempGrid.yPos = 0; } if (tempGrid.xPos == -1) { tempGrid.xPos = 0; } GridObjectPackage tempPackage = gridObjectRef[tempGrid]; tempPackage.gO.transform.position = grid[tempGrid.xPos, tempGrid.yPos].pos + tempPackage.offset; }
// Use this for initialization void Awake() { running = true; grid = new gridTile[gridSize, gridSize]; gridObjectXY = new Dictionary <GridObject, Vector2>(); gridObjectRef = new Dictionary <GridObject, GridObjectPackage>(); float depthIterator = 0; for (int i = 0; i < gridSize; i++) { for (int k = 0; k < gridSize; k++) { grid[i, k] = new gridTile(); grid[i, k].pos = (new Vector3(i, k, depthIterator++ *0.03f)) * gridSpacing; grid[i, k].gO = (GameObject)Instantiate(Resources.Load("Prefabs/GridMarker"), grid[i, k].pos, Quaternion.identity); } } gridGO = GameObject.FindGameObjectsWithTag("GridObject"); gridObjectArray = new GridObject[gridGO.Length]; for (int i = 0; i < gridGO.Length; i++) { GridObjectPackage tempPackage = new GridObjectPackage(); GridObject tempGrid = gridGO[i].GetComponent <GridObject>(); gridObjectArray[i] = tempGrid; Vector3 lScale = gridGO[i].transform.localScale; //additional sizes will always go down or left lScale = new Vector3(lScale.x * tempGrid.sizeX, lScale.y * tempGrid.sizeY, 1.0f) * gridSpacing; Vector3 posOffset = new Vector3(((-lScale.x * 0.5f) + 0.5f), ((-lScale.y * 0.5f) + 0.5f), 0.0f); gridGO[i].transform.position = grid[tempGrid.xPos, tempGrid.yPos].pos + posOffset; gridGO[i].transform.localScale = lScale; //fills the spaces in the grid GridFill(tempGrid); gridObjectXY[tempGrid] = new Vector2(tempGrid.xPos, tempGrid.yPos); //grid[tempGrid.xPos,tempGrid.yPos-1].gridObject = tempGrid; tempPackage.gO = tempGrid.gameObject; tempPackage.gridO = tempGrid; tempPackage.offset = posOffset; tempPackage.lScale = lScale; gridObjectRef[tempGrid] = tempPackage; } grid[(int)goalPos.x, (int)goalPos.y].isGoal = true; }
// Use this for initialization void Awake() { running = true; grid = new gridTile[gridSize,gridSize]; gridObjectXY = new Dictionary<GridObject, Vector2>(); gridObjectRef = new Dictionary<GridObject, GridObjectPackage>(); float depthIterator = 0; for(int i = 0; i < gridSize; i++){ for(int k = 0; k < gridSize; k++){ grid[i,k] = new gridTile(); grid[i,k].pos = (new Vector3(i,k,depthIterator++ * 0.03f)) * gridSpacing; grid[i,k].gO = (GameObject)Instantiate(Resources.Load("Prefabs/GridMarker"),grid[i,k].pos,Quaternion.identity); } } gridGO = GameObject.FindGameObjectsWithTag("GridObject"); gridObjectArray = new GridObject[gridGO.Length]; for(int i = 0; i < gridGO.Length; i++){ GridObjectPackage tempPackage = new GridObjectPackage(); GridObject tempGrid = gridGO[i].GetComponent<GridObject>(); gridObjectArray[i] = tempGrid; Vector3 lScale = gridGO[i].transform.localScale; //additional sizes will always go down or left lScale = new Vector3(lScale.x * tempGrid.sizeX, lScale.y * tempGrid.sizeY,1.0f) * gridSpacing; Vector3 posOffset = new Vector3(((-lScale.x * 0.5f)+0.5f),((-lScale.y * 0.5f)+0.5f),0.0f); gridGO[i].transform.position = grid[tempGrid.xPos,tempGrid.yPos].pos + posOffset; gridGO[i].transform.localScale = lScale; //fills the spaces in the grid GridFill(tempGrid); gridObjectXY[tempGrid] = new Vector2(tempGrid.xPos,tempGrid.yPos); //grid[tempGrid.xPos,tempGrid.yPos-1].gridObject = tempGrid; tempPackage.gO = tempGrid.gameObject; tempPackage.gridO = tempGrid; tempPackage.offset = posOffset; tempPackage.lScale = lScale; gridObjectRef[tempGrid] = tempPackage; } grid[(int)goalPos.x,(int)goalPos.y].isGoal = true; }