Exemplo n.º 1
0
    public void OnInteraction(Player player)
    {
        var selectedObject = player.selectedObject;

        if (selectedObject != null)
        {
            Debug.Log("Pot : You are holding something");
            if (selectedObject.isType(typeof(Seed).Name))//Planting
            {
                player.selectedObject.deSelected();
                player.setSelectedObject(null);
                Seed seed = (Seed)selectedObject;
                plant = Instantiate(seed.getPlantPrefab(), this.transform.position, Quaternion.identity, this.transform).GetComponent <Plant>();
                putPlantInPot();
                Debug.Log("Pot: You just planted a " + selectedObject.getName());
            }
            else if (selectedObject.isType(typeof(WaterCan).Name) && !isWatered)
            {
                Debug.Log("Pot: I like water");//Watering
                WaterCan waterCan = (WaterCan)selectedObject;
                waterCan.use(this);
            }
        }
        else if (selectedObject == null && isReadyForHarvest)
        {
            Debug.Log("Pot: It is harvest time!");//Harvesting
            harvest(player);
            //If the plant is ready, harvest
        }
    }
Exemplo n.º 2
0
    void Interaction(bool clicked, Vector3 mousePos)
    {
        itemPickedUp = false;
        foreach (var selected in selectedObjects)
        {
            if (selected.TryGetComponent(out ItemPickup itemPickup))
            {
                itemPickup.Interact();
                itemPickedUp = true;
            }
            if (!itemPickedUp)
            {
                Debug.Log("Object Selected: " + selected.name);
                if (clickMaster.currentObj != null)
                {
                    if (clickMaster.currentObj.parent.TryGetComponent(out InventorySlot slot))
                    {
                        if (slot.itemCount > 0)
                        {
                            if (clicked)
                            {
                                mousePos.z = transform.position.z;
                                if (Vector2.Distance(transform.position, mousePos) > 1f)
                                {
                                    targetPoint = mousePos;
                                    Instantiate(slot.item.plantObject, mousePos, Quaternion.identity);
                                }
                                else
                                {
                                    Instantiate(slot.item.plantObject, mousePos, Quaternion.identity);
                                }
                            }
                            else
                            {
                                Instantiate(slot.item.plantObject, targetArea.position, Quaternion.identity);
                            }

                            slot.RemoveItem();
                        }
                    }

                    if (clickMaster.currentObj.parent.name == "Tool Slot")
                    {
                        if (selected.tag == "Water")
                        {
                            Debug.Log("Filling Can");
                            WaterCan waterCan = clickMaster.currentObj.parent.GetComponent <WaterCan>();
                            if (waterCan.waterLevel < 8)
                            {
                                waterCan.waterLevel++;
                            }
                        }

                        if (selected.tag == "Plant" && selected.TryGetComponent(out Plant plant))
                        {
                            if (plant.plantState == Plant.PlantState.thirsty)
                            {
                                Debug.Log("Watering Plant");
                                WaterCan waterCan = clickMaster.currentObj.parent.GetComponent <WaterCan>();
                                if (waterCan.waterLevel > 0)
                                {
                                    plant.OnWater();
                                    waterCan.waterLevel--;
                                }
                                else
                                {
                                    waterCan.IconPop();
                                }
                            }
                        }
                    }
                }
            }
        }
    }