private void OnTriggerStay2D(Collider2D collision) { if (collision.gameObject.GetComponent <isHoldable>() == true && robotMoveScript.isGrabbing == false) { PlayerVariables.sendMessage("System", "Item detected."); AudioSource.PlayClipAtPoint(collectSound, Vector3.zero); collision.gameObject.SetActive(false); PlayerVariables.addToInventory(collision.gameObject.GetComponent <itemIdentifier>().name); } }
IEnumerator CheckingDirt() { for (byte i = 0; i < 4; i++) { PlayerVariables.sendMessage("System", "Checking..."); yield return(new WaitForSeconds(Random.Range(.3f, 1.2f))); } PlayerVariables.sendMessage("System", "[COMPLETE] Contamination Level: " + PlayerVariables.atmosphereContamination + "%"); PlayerVariables.addTaskProgress("testSoil1", 1); isGrabbing = false; }
public void GetDirtSample() { if (PlayerVariables.findInInventory("Dirt Checker") != null) { StartCoroutine(CheckingDirt()); } else { PlayerVariables.sendMessage("System", "Inventory does not include a dirt checker!"); } }
private void PopulatePanel() { //print("Debug Log: " + taskList[1].progress); Dictionary <string, int> itemizedInv = new Dictionary <string, int>(); foreach (string item in PlayerVariables.inventory) { if (Item.GetItemPrefab(item) != null) { if (!itemizedInv.ContainsKey(item)) { itemizedInv.Add(item, 1); } else { itemizedInv[item]++; } } } foreach (KeyValuePair <string, int> pair in itemizedInv) { string itemName = pair.Key; int itemAmount = pair.Value; string textLabel = itemName; if (itemAmount > 1) { textLabel += " (" + itemAmount + ")"; } GameObject itemUI = Instantiate(prefab, gameObject.GetComponent <Transform>()); itemUI.GetComponent <Transform>().Find("Text").GetComponent <Text>().text = textLabel; Button btn = itemUI.GetComponent <Button>(); btn.onClick.AddListener(() => { string removed = PlayerVariables.removeFromInventory(itemName); if (removed != null) { if (robotMoveScript.isGrabbing == false) { string newStr = itemName.Replace(" ", ""); GameObject pfClone = Instantiate(Resources.Load("Items/" + newStr) as GameObject); robotMoveScript.isGrabbing = true; robotMoveScript.chosenGameObject = pfClone; GameObject.Find("PickupRobot").GetComponent <canHoldItem>().pickUp(pfClone); gameObject.transform.parent.gameObject.SetActive(false); } else { PlayerVariables.sendMessage("Robot:", "Already have something in hand!"); } } }); } }
public void PlantWorldSeed() { if (itemSlot.GetChild(0).gameObject != null) { if (itemSlot.GetChild(0).gameObject.GetComponent <worldSeedPlantScript>()) { if (itemSlot.transform.GetChild(0).gameObject.GetComponent <itemIdentifier>().name == "Strong Purple Seed") { Vector3 savePos = itemSlot.transform.GetChild(0).position; Destroy(itemSlot.transform.GetChild(0).gameObject); robotMoveScript.chosenGameObject = null; robotMoveScript.isGrabbing = false; GameObject.Instantiate(Resources.Load("Plants/purple0") as GameObject, savePos + (0.3f * Vector3.down), Quaternion.Euler(0, 0, 0)); } if (itemSlot.transform.GetChild(0).gameObject.GetComponent <itemIdentifier>().name == "Red Seed") { Vector3 savePos = itemSlot.transform.GetChild(0).position; Destroy(itemSlot.transform.GetChild(0).gameObject); robotMoveScript.chosenGameObject = null; robotMoveScript.isGrabbing = false; if (Random.Range(0, 2) == 0) { GameObject.Instantiate(Resources.Load("Plants/tendril0") as GameObject, savePos + (0.3f * Vector3.down), Quaternion.Euler(0, 0, 0)); } else { GameObject.Instantiate(Resources.Load("Plants/snake0") as GameObject, savePos + (0.3f * Vector3.down), Quaternion.Euler(0, 0, 0)); } } if (itemSlot.transform.GetChild(0).gameObject.GetComponent <itemIdentifier>().name == "Grass Seed") { Vector3 savePos = itemSlot.transform.GetChild(0).position; Destroy(itemSlot.transform.GetChild(0).gameObject); robotMoveScript.chosenGameObject = null; robotMoveScript.isGrabbing = false; GameObject.Instantiate(Resources.Load("Plants/grass0") as GameObject, savePos + (0.3f * Vector3.down), Quaternion.Euler(0, 0, 0)); } } else { PlayerVariables.sendMessage("Robot:", "Not currently holding an outdoor plantable seed"); } } else { PlayerVariables.sendMessage("Robot:", "No seed in hand"); } }
// Update is called once per frame private void OnCollisionEnter2D(Collision2D collision) { if (robotMoveScript.isMovingToPosition == true) { if (robotMoveScript.isGrabbing == false) { robotMoveScript.chosenGameObject = gameObject; robotMoveScript.isSeekingPosition = false; } else { PlayerVariables.sendMessage("System", "Already grabbing something!"); robotMoveScript.isMovingToPosition = false; } } }
public void AddPlant() //purple seed { if (itemSlot.transform.GetChild(0).gameObject.GetComponent <itemIdentifier>().name == "Purple Seed") { if (gameObject.GetComponentsInChildren <Transform>().Length < maxCapacity) { if (energyBar.GetComponent <energyScript>().ReadEnergy() > 10) { energyBar.GetComponent <energyScript>().changeEnergy(-10); plantOrderIndex += 1; Destroy(itemSlot.transform.GetChild(0).gameObject); //itemSlot.transform.GetChild(0).gameObject.SetActive(false); robotMoveScript.isGrabbing = false; robotMoveScript.chosenGameObject = null; PlayerVariables.sendMessage("System:", "Unidentified lifeforms detected in plant shelter. Remove immediately."); GameObject plant = GameObject.Instantiate(Resources.Load("Plants/" + "purple0") as GameObject, gameObject.transform); plant.GetComponent <SpriteRenderer>().sortingOrder = plantOrderIndex; plant.GetComponent <PurplePlantGrowth>().growthRate = shelterGrowthRate; } else { PlayerVariables.sendMessage("Shelter", "Out of Energy!"); } } else { PlayerVariables.sendMessage("Plant Shelter", "This plant shelter is full!"); } } //green seed else if (itemSlot.transform.GetChild(0).gameObject.GetComponent <itemIdentifier>().name == "Green Seed") { if (gameObject.GetComponentsInChildren <Transform>().Length < maxCapacity) { if (energyBar.GetComponent <energyScript>().ReadEnergy() > 10) { energyBar.GetComponent <energyScript>().changeEnergy(-10); plantOrderIndex += 1; Destroy(itemSlot.transform.GetChild(0).gameObject); //itemSlot.transform.GetChild(0).gameObject.SetActive(false); robotMoveScript.isGrabbing = false; robotMoveScript.chosenGameObject = null; PlayerVariables.sendMessage("System:", "Lifeform detected in plant shelter. Attemping to Grow"); GameObject plant = GameObject.Instantiate(Resources.Load("Plants/" + "green0") as GameObject, gameObject.transform); plant.GetComponent <SpriteRenderer>().sortingOrder = plantOrderIndex; plant.GetComponent <plantGrowth>().growthRate = shelterGrowthRate; } else { PlayerVariables.sendMessage("Shelter", "Out of Energy!"); } } else { PlayerVariables.sendMessage("Plant Shelter", "This plant shelter is full!"); } } else if (itemSlot.transform.GetChild(0).gameObject.GetComponent <itemIdentifier>().name == "Brocc Seed") { if (gameObject.GetComponentsInChildren <Transform>().Length < maxCapacity) { if (energyBar.GetComponent <energyScript>().ReadEnergy() > 10) { energyBar.GetComponent <energyScript>().changeEnergy(-10); plantOrderIndex += 1; Destroy(itemSlot.transform.GetChild(0).gameObject); //itemSlot.transform.GetChild(0).gameObject.SetActive(false); robotMoveScript.isGrabbing = false; robotMoveScript.chosenGameObject = null; PlayerVariables.sendMessage("System:", "Ohhhh yeaaaa, broccoli DETECTED"); GameObject plant = GameObject.Instantiate(Resources.Load("Plants/" + "brocc0") as GameObject, gameObject.transform); plant.GetComponent <SpriteRenderer>().sortingOrder = plantOrderIndex; plant.GetComponent <plantGrowth>().growthRate = shelterGrowthRate; } else { PlayerVariables.sendMessage("Shelter", "Out of Energy!"); } } else { PlayerVariables.sendMessage("Plant Shelter", "This plant shelter is full!"); } } else { PlayerVariables.sendMessage("Plant Shelter", "You aren't holding a plant!"); } }