// Update is called once per frame void Update() { if (oog.placed) { if (currTime >= growthTime) { Debug.Log("YoungTree1 creates YoungTree2"); GameObject youngTree2 = Instantiate(YoungTree2); youngTree2.transform.position = gameObject.transform.position; youngTree2.transform.rotation = gameObject.transform.rotation; ObjectOnGrid oog2 = youngTree2.GetComponent <ObjectOnGrid>(); oog2.placed = true; oog2.SetNodes(oog.Nodes); //for (int i = 0; i < oog2.Nodes.GetLength(0); i++) //{ // for (int j = 0; j < oog2.Nodes.GetLength(1); j++) // { // //Debug.Log("i: " + i + " j: " + j + " | grid x:" + oog2.Nodes[i , j].gridX + " grid y: " + oog2.Nodes[i , j].gridY); // } //} Destroy(gameObject); } else { currTime += Time.deltaTime; } } }
// Update is called once per frame void Update() { if (oog.placed) { if (currTime >= growthTime) { Debug.Log("YoungTree2 creates Tree"); GameObject tree = Instantiate(Tree); tree.transform.position = gameObject.transform.position; tree.transform.rotation = gameObject.transform.rotation; ObjectOnGrid oogTree = tree.GetComponent <ObjectOnGrid>(); oogTree.placed = true; for (int i = 0; i < oog.Nodes.GetLength(0); i++) { for (int j = 0; j < oog.Nodes.GetLength(1); j++) { Debug.Log("i: " + i + " j: " + j + " | grid x:" + oog.Nodes[i, j].gridX + " grid y: " + oog.Nodes[i, j].gridY); } } oogTree.SetNodes(oog.Nodes); Destroy(gameObject); } else { currTime += Time.deltaTime; } } }
// Update is called once per frame void Update() { if (foodLeft == 0) { GameObject bushWithoutBerries = Instantiate(BushWithoutBerries); bushWithoutBerries.transform.position = gameObject.transform.position; bushWithoutBerries.transform.rotation = gameObject.transform.rotation; ObjectOnGrid oogNoBerryBush = bushWithoutBerries.GetComponent <ObjectOnGrid>(); oogNoBerryBush.placed = true; oogNoBerryBush.SetNodes(GetComponent <ObjectOnGrid>().Nodes); Destroy(gameObject); } }
// Update is called once per frame void Update() { if (currTime >= growthTime) { GameObject berryBush = Instantiate(BerryBush); berryBush.transform.position = gameObject.transform.position; berryBush.transform.rotation = gameObject.transform.rotation; ObjectOnGrid oogBerryBush = berryBush.GetComponent <ObjectOnGrid>(); oogBerryBush.placed = true; oogBerryBush.SetNodes(GetComponent <ObjectOnGrid>().Nodes); Destroy(gameObject); } else { currTime += Time.deltaTime; } }
public void PlantTree() { GameObject youngTree = Instantiate(fhs.YoungTree); youngTree.transform.position = newTreeLocation.transform.position; ObjectOnGrid oogNewTree = youngTree.GetComponent <ObjectOnGrid>(); oogNewTree.placed = true; oogNewTree.SetNodes(new Node[, ] { { targetNode } }); newTreeLocation = null; targetNode = null; state = States.CommingBack; unit.MoveTo(fhs.InitialPosition.transform.position); }
// Update is called once per frame void Update() { if (currentBuilding != null) { ObjectOnGrid data = currentBuilding.GetComponent <ObjectOnGrid>(); RaycastHit hit = new RaycastHit(); Ray ray = camera.ScreenPointToRay(Input.mousePosition); Physics.Raycast(ray, out hit, Mathf.Infinity); Vector3 pos = new Vector3(hit.point.x, 0, hit.point.z); Node rayPointNode = grid.NodeFromWorldPoint(hit.point); Vector3 rayPointNodePos = rayPointNode.worldPosition; ObjectOnGrid oog = currentBuilding.GetComponent <ObjectOnGrid>(); NavMeshObstacle navMeshObstacle = currentBuilding.GetComponent <NavMeshObstacle>(); currentBuilding.transform.position = rayPointNodePos + new Vector3((oog.takesSpaceX + 1) % 2 * grid.nodeDiameter / 2, 0.5f, (oog.takesSpaceY + 1) % 2 * grid.nodeDiameter / 2); FortressScript Fortress = FindObjectOfType <FortressScript>(); if (Fortress == null) { ShowAvailableToBuild(currentBuilding.transform.position); } else { ShowAvailableToBuild(currentBuilding.transform.position, Fortress.transform.position, Fortress.Ranges[Fortress.Level - 1], oog.takesSpaceX, oog.takesSpaceY); } if (Input.GetMouseButtonDown(0)) { Node node = grid.NodeFromWorldPoint(currentBuilding.position); if (Fortress != null) { //Debug.Log("Checking distance..."); if (!grid.CheckDistance(rayPointNode.gridX, rayPointNode.gridY, data.takesSpaceX, data.takesSpaceY, Fortress.transform.position, Fortress.Ranges[Fortress.Level - 1])) { return; } //Debug.Log("Distance ok. Checking path..."); FortressPos = Fortress.SpawnPosition.position; NavMeshPath path = new NavMeshPath(); NavMesh.CalculatePath(FortressPos, currentBuilding.transform.position, NavMesh.AllAreas, path); if (path.status != NavMeshPathStatus.PathComplete) { return; } //Debug.Log("Path ok."); } if (grid.UpdateGrid(rayPointNode.gridX, rayPointNode.gridY, data.takesSpaceX, data.takesSpaceY)) { oog.SetNodes(grid.GetNodes(rayPointNode.gridX, rayPointNode.gridY, data.takesSpaceX, data.takesSpaceY)); data.gridPosX = node.gridX; data.gridPosY = node.gridY; rm.DecreaseResources(ResourceManager.Resources.Wood, oog.costWood); rm.DecreaseResources(ResourceManager.Resources.Stone, oog.costStone); oog.placed = true; navMeshObstacle.enabled = true; scoreManager.AddScore(oog.scoreBonus); currentBuilding = null; resetRest(0, 0); } if (oog.objectName == "Road") { SetItem(lastBuilding); } } if (Input.GetMouseButtonDown(1)) { Destroy(currentBuilding.gameObject); resetRest(0, 0); } if (Input.GetKeyDown("r")) { currentBuilding.Rotate(Vector3.forward, 90); } } }