// awake happens too soon like a bitch void Update() { RoadGenerator rg = gameObject.GetComponent <RoadGenerator>(); int r = Random.Range(0, 100); if (r < GrassPopulationManager.instance.ChanceFences) { int f = Random.Range(0, GrassPopulationManager.Fences.Length); GameObject FenceTemplate = GrassPopulationManager.Fences[f]; int d = 2 * Random.Range(0, 4); rg.DoHits(); WorldTile tiled = rg.GetNeighbours()[d]; if (tiled && tiled.GetComponent <GrassPopulator>() && tiled.GetComponent <GrassPopulator>().FenceDir == RoadGenerator.Wrap0to7(d - 4)) { //Debug.Log("fence collision prevented"); } else { GameObject fence = Instantiate(FenceTemplate, transform.position + new Vector3((RoadGenerator.Xoffset(d) * WorldTileManager.TILE_SIZE) / 2, 0, (RoadGenerator.Zoffset(d) * WorldTileManager.TILE_SIZE) / 2), Quaternion.identity, transform); fence.transform.Rotate(0, d * 45 - 90, 0); FenceDir = d; } } int t = Random.Range(0, GrassPopulationManager.instance.MaximumTreeDensity); List <Vector3> trees = new List <Vector3>(); trees.Clear(); float x, y; x = y = 0.0f; bool bCollides = true; for (int i = 0; i < t; ++i) { bCollides = true; while (bCollides) { x = Random.Range(-9.0f, 9.0f); y = Random.Range(-9.0f, 9.0f); bCollides = false; foreach (Vector3 treepos in trees) { if ((treepos - new Vector3(x, 0, y)).magnitude < 4.0f) { bCollides = true; } } } trees.Add(new Vector3(x, 0, y)); Instantiate(GrassPopulationManager.Tree, transform.position + new Vector3(x, 0, y), Quaternion.identity, transform); } enabled = false; }
void setNodesNearMeToUnwalkable() { if (nodesISetToUnwalkable == null) { nodesISetToUnwalkable = new List <WorldTile> (); } else { resetNodes(); } WorldTile pos = WorldBuilder.me.getNearest(this.transform.position); for (int x = -2; x < 2; x++) { for (int y = -2; y < 2; y++) { WorldTile wt = WorldBuilder.me.worldTiles [pos.gridX + x, pos.gridY + y].GetComponent <WorldTile>(); if (wt.walkable == true) { ////Debug.Log (wt.gameObject.name + " set to unwalkable"); wt.GetComponent <SpriteRenderer> ().color = Color.blue; wt.walkable = false; nodesISetToUnwalkable.Add(wt); ThreadedPathfindInterface.me.nodes [wt.gridX, wt.gridY].walkable = false; } } } }
void changeNodesNearMe() { WorldTile pos = WorldBuilder.me.getNearest(this.transform.position); for (int x = -2; x < 2; x++) { for (int y = -2; y < 2; y++) { WorldTile wt = WorldBuilder.me.worldTiles [pos.gridX + x, pos.gridY + y].GetComponent <WorldTile>(); if (wt.walkable == true) { ////Debug.Log (wt.gameObject.name + " set to unwalkable"); wt.GetComponent <SpriteRenderer> ().color = Color.blue; //wt.walkable = false; float modifier = 100 + (1000 - (Vector2.Distance(this.transform.position, wt.gameObject.transform.position) * 100)); //Debug.Log (modifier); wt.tempModifiers = Mathf.RoundToInt(modifier); //nodesISetToUnwalkable.Add (wt); try{ ThreadedPathfindInterface.me.nodes [wt.gridX, wt.gridY].tempModifiers = Mathf.RoundToInt(modifier); } catch { //Debug.LogError ("Could not find threaded tiles"); continue; } } } } }
void reEnableNodeNearSpawns() { foreach (Transform t in copSpawnPoints) { WorldTile wt = WorldBuilder.me.getNearest(this.transform.position); if (wt.walkable == false) { ////Debug.Log (wt.gameObject.name + " set to unwalkable"); wt.GetComponent <SpriteRenderer> ().color = Color.cyan; if (wt.modifier >= 100000) { wt.modifier -= 100000; ThreadedPathfindInterface.me.nodes [wt.gridX, wt.gridY].modifier -= 100000; ThreadedPathfindInterface.me.nodes [wt.gridX, wt.gridY].walkable = true; } //nodesISetToUnwalkable.Add (wt); } } }
private void HandleClicks() { if (!EventSystem.current.IsPointerOverGameObject()) { if ((Input.GetMouseButtonUp(0) && matchTimer.matchStarted)) { Ray screenToWorld = viewportCamera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(screenToWorld, out RaycastHit raycastHit)) { clickerAudio.PlayInspect(); Collider other = raycastHit.collider; switch (other.tag) { case "Building": ClearSelections(); selectedBuilding = other.GetComponentInParent <Building>(); selectedBuilding.FocusOnBuilding(); upgradeMenuObj.SetActive(true); //upgradeMenu.PopulateList(selectedBuilding.upgrades); upgradeMenu.SetSelectedBuilding(selectedBuilding); break; case "Plot": ClearSelections(); Building.UnfocusAllBuildings(); selectedPlot = other.GetComponentInParent <Plot>(); selectedPlot.FocusOnPlot(); if (selectedPlot.size == (Plot.PlotSize) 0) { buildMenuObj[2].SetActive(true); } else if (selectedPlot.size == (Plot.PlotSize) 1) { buildMenuObj[0].SetActive(true); } else if (selectedPlot.size == (Plot.PlotSize) 2) { buildMenuObj[1].SetActive(true); } break; case "Forest": ClearSelections(); selectedForest = other.GetComponent <Forest>(); buyTileMenu.SetSelectedTile(selectedForest); buyMenuObj.SetActive(true); if (!selectedForest.finished) { buyTileMenu.buildButtons[0].SetActive(true); } if (selectedForest.building) { buyTileMenu.buildButtons[0].SetActive(false); buyTileMenu.buildButtons[1].SetActive(true); buyTileMenu.buildButtons[1].GetComponent <Button>().interactable = false; } if (selectedForest.finished) { buyTileMenu.buildButtons[1].SetActive(true); buyTileMenu.buildButtons[1].GetComponent <Button>().interactable = true; } break; case "Rock": ClearSelections(); selectedRock = other.GetComponent <Rock>(); buyTileMenu.SetSelectedTile(selectedRock); buyMenuObj.SetActive(true); if (!selectedRock.finished) { buyTileMenu.buildButtons[3].SetActive(true); } if (selectedRock.building) { buyTileMenu.buildButtons[3].SetActive(false); buyTileMenu.buildButtons[4].SetActive(true); buyTileMenu.buildButtons[4].GetComponent <Button>().interactable = false; } if (selectedRock.finished) { buyTileMenu.buildButtons[4].SetActive(true); buyTileMenu.buildButtons[4].GetComponent <Button>().interactable = true; } break; case "WorldTile": ClearSelections(); selectedTile = other.GetComponent <WorldTile>(); selectedTile.GetComponent <Animator>().SetBool("Focused", true); buyTileMenu.SetSelectedTile(selectedTile); if (!selectedTile.purchased) { buyMenuObj.SetActive(true); buyTileMenu.buildButtons[2].SetActive(true); } break; case "SkullIsland": bombCounter++; Debug.Log(bombCounter); nukeSource = nukeAudio.GetComponent <AudioSource>(); nukeSource.PlayOneShot(nukeAudio.dontDoIt[bombCounter - 1]); if (bombCounter == 5) { nuke = other.GetComponent <NukeTime>(); nuke.nukeTime(); } break; default: ClearSelections(); break; } } } } }