private void InitialCellBehaviour() { allCells = tgs.cells; foreach (Cell cell in allCells) { int cellIndex = tgs.CellGetIndex(cell); //green = wood; if (tgs.CellGetTexture(cellIndex) == tgs.textures[1]) { tgs.CellSetCrossCost(cellIndex, 2); tgs.CellToggleRegionSurface(cellIndex, false, tgs.textures[1]); tgs.CellSetGroup(cellIndex, group1); } //apple = swamp else if (tgs.CellGetTexture(cellIndex) == tgs.textures[2]) { tgs.CellSetCrossCost(cellIndex, 4); tgs.CellToggleRegionSurface(cellIndex, false, tgs.textures[2]); tgs.CellSetGroup(cellIndex, group2); } //map = mountain else if (tgs.CellGetTexture(cellIndex) == tgs.textures[3]) { tgs.CellSetCanCross(cellIndex, false); tgs.CellToggleRegionSurface(cellIndex, false, tgs.textures[3]); } } }
void MarkAllGameObjects() { GameObject[] gameobjects; gameobjects = GameObject.FindGameObjectsWithTag("Enemy"); foreach (GameObject g in gameobjects) { Cell cell = tgs.CellGetAtPosition(g.transform.position, true); int cellIndex = tgs.CellGetIndex(cell); tgs.CellSetCrossCost(cellIndex, 12000); tgs.CellSetGroup(cellIndex, CELL_ENEMY); } }
protected void TraverseCells() { isMoving = true; animator.Play("Run"); var cellCenter = movePath[cellIndex]; if (!rotationSet) { Quaternion newRotation = Quaternion.Euler(transform.eulerAngles.x, directionToLook(cellCenter), transform.eulerAngles.z); transform.rotation = newRotation; rotationSet = true; } Vector3 currentPosition = this.transform.position; if (Vector3.Distance(currentPosition, cellCenter) > .1f) { string direction = currentlyLooking(); float step = moveSpeed * Time.deltaTime; transform.position = Vector3.MoveTowards(transform.position, cellCenter, step); } else { rotationSet = false; if (cellIndex < movePath.Count - 1) { cellIndex += 1; } else { animator.Play("Idle"); cellIndex = 0; movePath = new List <Vector3>(); transform.position = Vector3.Lerp(transform.position, cellCenter, 0.5f); Cell occupyingCell = TGSInterface.CellAtPosition(cellCenter); currentCellIndex = occupyingCell.index; int mask = TGSInterface.CELL_MASKS[EntityType.ToUpper()]; tgs.CellSetGroup(occupyingCell.index, mask); isMoving = false; OnReachedDestination.Invoke(); } } }