public void cutWeed() { GameObject cropsHandler = GameObject.FindGameObjectWithTag("CropHandler"); CropBehaviour[] crops = cropsHandler.GetComponentsInChildren <CropBehaviour> (); CreateSoil sl = FindObjectOfType(typeof(CreateSoil)) as CreateSoil; soil = sl.allSquares; for (int i = 0; i < soil.Count; i++) { if (soil [i].getSoil().GetComponent <SoilCollision> ().collision == true && (soil [i].getType().Equals(Soil.SoilTypes.PLOWED) || soil [i].getType().Equals(Soil.SoilTypes.PLANTED))) { Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if ((hit.transform.tag == "crop" && (hit.transform.position.x == soil [i].getSoil().transform.position.x&& hit.transform.position.z == soil [i].getSoil().transform.position.z))) { StartCoroutine(WaitForCut(i)); Destroy(crops [i].gameObject); break; } } } } }
public void waterSoil() { GameObject cropsHandler = GameObject.FindGameObjectWithTag("CropHandler"); CropBehaviour[] crops = cropsHandler.GetComponentsInChildren <CropBehaviour> (); CreateSoil sl = FindObjectOfType(typeof(CreateSoil)) as CreateSoil; soil = sl.allSquares; if (currentCapacity > 0) { currentCapacity -= 1; Debug.Log(currentCapacity); for (int i = 0; i < soil.Count; i++) { if (soil [i].getSoil().GetComponent <SoilCollision> ().collision == true && (soil [i].getType().Equals(Soil.SoilTypes.PLOWED) || soil [i].getType().Equals(Soil.SoilTypes.PLANTED))) { Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (soil [i].getSoil().transform.gameObject.Equals(hit.transform.gameObject) || (hit.transform.tag == "crop" && (hit.transform.position.x == soil [i].getSoil().transform.position.x&& hit.transform.position.z == soil [i].getSoil().transform.position.z))) { StartCoroutine(WaitForTextureChange(i)); break; } } } } } else { warning.transform.Find("Warnings").gameObject.SetActive(true); warning.GetComponentInChildren <Text>().text = "Watering can is empty"; StartCoroutine(setPanelInactive()); } }
//In this function a ray cast is thrown to check if we can plow the soil square //if we can, the soil will be plowed and its state will change public void plowSoil() { CreateSoil s = FindObjectOfType(typeof(CreateSoil)) as CreateSoil; soil = s.allSquares; for (int i = 0; i < soil.Count; i++) { if (soil [i].getSoil().GetComponent <SoilCollision> ().collision == true && soil [i].getType().Equals(Soil.SoilTypes.NOTPLOWED)) { Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (soil [i].getSoil().transform.gameObject.Equals(hit.transform.gameObject)) { Debug.Log("Boom"); playerStamina.loseStamina(5); StartCoroutine(waitForTextureChange(i)); } } } } }
public void plantSeeds() { typeOfSeeds(); CreateSoil sl = FindObjectOfType(typeof(CreateSoil)) as CreateSoil; soil = sl.allSquares; for (int i = 0; i < soil.Count; i++) { if (soil [i].getSoil().GetComponent <SoilCollision> ().collision == true && (soil [i].getType().Equals(Soil.SoilTypes.PLOWED) || soil [i].getType().Equals(Soil.SoilTypes.WATERED))) { Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (soil [i].getSoil().transform.gameObject.Equals(hit.transform.gameObject)) { removeSeedsButton(); playerStamina.loseStamina(5); Transform s = Instantiate(seeds.transform, new Vector3((soil [i].getSoil().transform.position.x), 0f, soil [i].getSoil().transform.position.z), soil [i].getSoil().transform.rotation) as Transform; s.SetParent(seedsParent); if (soil [i].getType() == Soil.SoilTypes.WATERED) { soil [i].soilType = Soil.SoilTypes.WATEREDANDPLATED; } else { soil [i].soilType = Soil.SoilTypes.PLANTED; } break; } } } } }
// Use this for initialization void Start() { soil = FindObjectOfType(typeof(CreateSoil)) as CreateSoil; allS = soil.allSquares; crops = FindObjectOfType <MockCropDB> (); timeManager = FindObjectOfType <TimeManager> (); state = Crops.cropStates.SEED; col = this.gameObject.AddComponent(typeof(MeshCollider)) as MeshCollider; col.convex = true; if (this.gameObject.name.Contains("cherryseeds")) { treeName = crops.cherry.name; treeDescription = crops.cherry.description; daysToNextStage = crops.cherry.daysToStage1; dayToS1 = crops.cherry.daysToStage1; dayToS2 = crops.cherry.daysToStage2; dayToHarvest = crops.cherry.daysToHarvest; season = crops.cherry.season; staminaRecovery = crops.cherry.staminaRecovery; code = crops.cherry.code; price = crops.cherry.price; } else if (this.gameObject.name.Contains("peachseeds")) { treeName = crops.peach.name; treeDescription = crops.peach.description; daysToNextStage = crops.peach.daysToStage1; dayToS1 = crops.peach.daysToStage1; dayToS2 = crops.peach.daysToStage2; dayToHarvest = crops.peach.daysToHarvest; season = crops.peach.season; staminaRecovery = crops.peach.staminaRecovery; code = crops.peach.code; price = crops.peach.price; } else if (this.gameObject.name.Contains("appleseeds")) { treeName = crops.apple.name; treeDescription = crops.apple.description; daysToNextStage = crops.apple.daysToStage1; dayToS1 = crops.apple.daysToStage1; dayToS2 = crops.apple.daysToStage2; dayToHarvest = crops.apple.daysToHarvest; season = crops.apple.season; staminaRecovery = crops.apple.staminaRecovery; code = crops.apple.code; price = crops.apple.price; } else if (this.gameObject.name.Contains("orangeseeds")) { treeName = crops.orange.name; treeDescription = crops.orange.description; daysToNextStage = crops.orange.daysToStage1; dayToS1 = crops.orange.daysToStage1; dayToS2 = crops.orange.daysToStage2; dayToHarvest = crops.orange.daysToHarvest; season = crops.orange.season; staminaRecovery = crops.orange.staminaRecovery; code = crops.orange.code; price = crops.orange.price; } M_ST1 = Resources.Load <Renderer> ("Trees/" + treeName + "Tree/" + treeName + "ST1").sharedMaterials; M_ST2 = Resources.Load <Renderer> ("Trees/" + treeName + "Tree/" + treeName + "ST2").sharedMaterials; M_HARVEST = Resources.Load <Renderer> ("Trees/" + treeName + "Tree/" + treeName + "ST3").sharedMaterials; MF_ST1 = Resources.Load <MeshFilter> ("Trees/" + treeName + "Tree/" + treeName + "ST1"); MF_ST2 = Resources.Load <MeshFilter> ("Trees/" + treeName + "Tree/" + treeName + "ST2"); MF_HARVEST = Resources.Load <MeshFilter> ("Trees/" + treeName + "Tree/" + treeName + "ST3"); }
// Use this for initialization void Start() { soil = FindObjectOfType(typeof(CreateSoil)) as CreateSoil; allS = soil.allSquares; crops = FindObjectOfType <MockCropDB> (); timeManager = FindObjectOfType <TimeManager> (); dayPlanted = (int)timeManager.getDay(); state = Crops.cropStates.SEED; dryCrop = Resources.Load <Material> ("Materials/mockcrops/Dry"); this.gameObject.transform.Rotate(-90, 0, 0); if (this.gameObject.name.Contains("turnipseeds")) { cropName = crops.turnip.getName(); staminaRecovery = crops.turnip.staminaRecovery; cropDescription = crops.turnip.getDescription(); dayToS1 = dayPlanted + crops.turnip.getS1Days(); dayToS2 = dayToS1 + crops.turnip.getS2Days(); dayToHarvest = dayToS2 + crops.turnip.getHarvestDays(); season = crops.turnip.getSeason(); code = crops.turnip.code; price = crops.turnip.price; } else if (this.gameObject.name.Contains("cabbageseeds")) { cropName = crops.cabbage.getName(); staminaRecovery = crops.cabbage.staminaRecovery; cropDescription = crops.cabbage.getDescription(); dayToS1 = dayPlanted + crops.cabbage.getS1Days(); dayToS2 = dayToS1 + crops.cabbage.getS2Days(); dayToHarvest = dayToS2 + crops.cabbage.getHarvestDays(); season = crops.cabbage.getSeason(); code = crops.cabbage.code; price = crops.cabbage.price; } else if (this.gameObject.name.Contains("carrotseeds")) { cropName = crops.carrot.getName(); staminaRecovery = crops.carrot.staminaRecovery; cropDescription = crops.carrot.getDescription(); dayToS1 = dayPlanted + crops.carrot.getS1Days(); dayToS2 = dayToS1 + crops.carrot.getS2Days(); dayToHarvest = dayToS2 + crops.carrot.getHarvestDays(); season = crops.carrot.getSeason(); code = crops.carrot.code; price = crops.carrot.price; } else if (this.gameObject.name.Contains("onionseeds")) { cropName = crops.onion.getName(); staminaRecovery = crops.onion.staminaRecovery; cropDescription = crops.onion.getDescription(); dayToS1 = dayPlanted + crops.onion.getS1Days(); dayToS2 = dayToS1 + crops.onion.getS2Days(); dayToHarvest = dayToS2 + crops.onion.getHarvestDays(); season = crops.onion.getSeason(); code = crops.onion.code; price = crops.onion.price; } else if (this.gameObject.name.Equals("radishseeds(Clone)")) { cropName = crops.radish.getName(); staminaRecovery = crops.radish.staminaRecovery; cropDescription = crops.radish.getDescription(); dayToS1 = dayPlanted + crops.radish.getS1Days(); dayToS2 = dayToS1 + crops.radish.getS2Days(); dayToHarvest = dayToS2 + crops.radish.getHarvestDays(); season = crops.radish.getSeason(); code = crops.radish.code; price = crops.radish.price; } else if (this.gameObject.name.Contains("spinachseeds")) { cropName = crops.spinach.getName(); staminaRecovery = crops.spinach.staminaRecovery; cropDescription = crops.spinach.getDescription(); dayToS1 = dayPlanted + crops.spinach.getS1Days(); dayToS2 = dayToS1 + crops.spinach.getS2Days(); dayToHarvest = dayToS2 + crops.spinach.getHarvestDays(); season = crops.spinach.getSeason(); code = crops.spinach.code; price = crops.spinach.price; } else if (this.gameObject.name.Contains("daikon radishseeds")) { cropName = crops.daikonRadish.getName(); staminaRecovery = crops.daikonRadish.staminaRecovery; cropDescription = crops.daikonRadish.getDescription(); dayToS1 = dayPlanted + crops.daikonRadish.getS1Days(); dayToS2 = dayToS1 + crops.daikonRadish.getS2Days(); dayToHarvest = dayToS2 + crops.daikonRadish.getHarvestDays(); season = crops.daikonRadish.getSeason(); code = crops.daikonRadish.code; price = crops.daikonRadish.price; } else if (this.gameObject.name.Contains("broccoliseeds")) { cropName = crops.broccoli.getName(); staminaRecovery = crops.broccoli.staminaRecovery; cropDescription = crops.broccoli.getDescription(); dayToS1 = dayPlanted + crops.broccoli.getS1Days(); dayToS2 = dayToS1 + crops.broccoli.getS2Days(); dayToHarvest = dayToS2 + crops.broccoli.getHarvestDays(); season = crops.broccoli.getSeason(); code = crops.broccoli.code; price = crops.broccoli.price; } M_ST1 = Resources.Load <Renderer> ("Crops/" + cropName + "/" + cropName + "ST1").sharedMaterials; M_ST2 = Resources.Load <Renderer> ("Crops/" + cropName + "/" + cropName + "ST2").sharedMaterials; M_HARVEST = Resources.Load <Renderer> ("Crops/" + cropName + "/" + cropName + "ST3").sharedMaterials; MF_ST1 = Resources.Load <MeshFilter> ("Crops/" + cropName + "/" + cropName + "ST1"); MF_ST2 = Resources.Load <MeshFilter> ("Crops/" + cropName + "/" + cropName + "ST2"); MF_HARVEST = Resources.Load <MeshFilter> ("Crops/" + cropName + "/" + cropName + "ST3"); }
public void recollect() { GameObject cropsHandler = GameObject.FindGameObjectWithTag("CropHandler"); CropBehaviour[] crops = cropsHandler.GetComponentsInChildren <CropBehaviour> (); tree = cropsHandler.GetComponentsInChildren <TreeBehaviour> (); Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; CreateSoil sl = FindObjectOfType(typeof(CreateSoil)) as CreateSoil; soil = sl.allSquares; MockCropDB cropDB = FindObjectOfType <MockCropDB> (); if (Physics.Raycast(ray, out hit)) { if (hit.transform.tag == "crop") { for (int i = 0; i < crops.Length; i++) { if (crops [i].GetComponent <CropCollision> () != null) { if (crops [i].GetComponent <CropCollision> ().collision == true && hit.transform.Equals(crops [i].transform)) { foreach (Soil s in soil) { if (s.getSoil().transform.position.x == crops [i].transform.position.x && s.getSoil().transform.position.z == crops [i].transform.position.z) { if (s.getType().Equals(Soil.SoilTypes.PLANTED)) { s.soilType = Soil.SoilTypes.PLOWED; } if (s.getType().Equals(Soil.SoilTypes.WATEREDANDPLATED)) { s.soilType = Soil.SoilTypes.WATERED; } } } buttonToPress.hidePanel(); Destroy(crops [i].transform.gameObject); InventoryItem item = new InventoryItem(crops [i].cropName, crops [i].cropDescription, crops [i].staminaRecovery, crops[i].price, crops[i].code, InventoryItem.inventoryTypes.EDIBLE); inventory.addItem(item, 9); break; } } } } else if (hit.transform.tag == "SpawnItem") { Debug.Log(Vector3.Distance(hit.transform.position, player.transform.position) < 10); string name = hit.transform.name.Replace("(Clone)", ""); if (Vector3.Distance(hit.transform.position, player.transform.position) < 10) { if (hit.transform.name.Contains("Branch")) { InventoryItem item = new InventoryItem(name, "A branch, nothing more, nothing less.", 0, 1, 20, InventoryItem.inventoryTypes.NOTEDIBLE); inventory.addItem(item, 1); Destroy(hit.transform.gameObject); } else if (hit.transform.name.Contains("Apricot")) { InventoryItem item = new InventoryItem(name, "Wild item which you can eat or sell. Only found in spring.", 3, 20, 16, InventoryItem.inventoryTypes.EDIBLE); inventory.addItem(item, 1); Destroy(hit.transform.gameObject); } else if (hit.transform.name.Contains("Plum")) { InventoryItem item = new InventoryItem(name, "Wild item which you can eat or sell. Only found in summer.", 3, 20, 16, InventoryItem.inventoryTypes.EDIBLE); inventory.addItem(item, 1); Destroy(hit.transform.gameObject); } else if (hit.transform.name.Contains("Black")) { InventoryItem item = new InventoryItem(name, "Wild item which you can eat or sell. Only found in fall.", 3, 20, 16, InventoryItem.inventoryTypes.EDIBLE); inventory.addItem(item, 1); Destroy(hit.transform.gameObject); } else if (hit.transform.name.Contains("Goji")) { InventoryItem item = new InventoryItem(name, "Wild item which you can eat or sell. Only found in winter", 3, 20, 16, InventoryItem.inventoryTypes.EDIBLE); inventory.addItem(item, 1); Destroy(hit.transform.gameObject); } } } else if (hit.transform.tag == "tree") { for (int j = 0; j < tree.Length; j++) { if (tree [j].GetComponent <TreeCollision> () != null) { if (tree [j].GetComponent <TreeCollision> ().collision == true && hit.transform.Equals(tree [j].transform)) { tree [j].daysToNextStage = tree [j].dayToHarvest; tree[j].gameObject.GetComponent <Renderer> ().sharedMaterials = tree[j].M_ST2; tree[j].GetComponent <MeshFilter> ().sharedMesh = tree[j].MF_ST2.sharedMesh; InventoryItem fruit = new InventoryItem(tree [j].treeName, tree [j].treeDescription, tree [j].staminaRecovery, tree [j].price, tree [j].code, InventoryItem.inventoryTypes.EDIBLE); inventory.addItem(fruit, 3); break; } } } } } }
// Use this for initialization void Start() { soil = FindObjectOfType(typeof(CreateSoil)) as CreateSoil; watterM = Resources.Load <Material> ("Materials/Watered"); }