Exemplo n.º 1
0
    private void Update()
    {
        if (Input.GetKeyUp(keyInteract))
        {
            if (target != null)
            {
                switch (targetTag)
                {
                case "Seedbag":
                    Seedbag seedbag = target.GetComponent <Seedbag>();
                    if (seedbag != null && product == null)
                    {
                        seedbag.Interact(crop, hasCan, this);
                    }
                    break;

                case "Field":
                    Field field = target.GetComponent <Field>();
                    if (field != null && product == null)
                    {
                        field.Interact(crop, hasCan, this);
                    }
                    break;

                case "Can":
                    Can can = target.GetComponent <Can>();
                    if (can != null && product == null)
                    {
                        can.Interact(crop, hasCan, this);
                    }
                    break;

                case "Table":
                    Table table = target.GetComponent <Table>();
                    if (table != null)
                    {
                        table.Interact(crop, product, hasCan, this);
                    }
                    break;

                case "Trash":
                    Trash trash = target.GetComponent <Trash>();
                    if (trash != null)
                    {
                        trash.Interact(crop, product, hasCan, this);
                    }
                    break;

                case "Tree":
                    Trees tree = target.GetComponent <Trees>();
                    if (tree != null)
                    {
                        tree.Interact(crop, hasCan, this);
                    }
                    break;

                case "ProductionB":
                    ProductionBuilding building = target.GetComponent <ProductionBuilding>();
                    if (building != null)
                    {
                        if (crop != null)
                        {
                            product = crop.MakeProductFromCrop();
                            if (product != null)
                            {
                                building.Interact(product, this);
                            }
                        }
                        else if (product != null)
                        {
                            building.Interact(product, this);
                        }
                        else if (crop == null)
                        {
                            building.Interact(null, this);
                        }
                    }
                    break;

                case "SpawnedItems":
                    SpawnItems items = target.GetComponent <SpawnItems>();
                    if (items != null && product == null)
                    {
                        items.Interact(crop, hasCan, this);
                    }
                    break;

                case "Well":
                    Well well = target.GetComponent <Well>();
                    if (well != null && product == null)
                    {
                        well.Interact(crop, hasCan, this);
                    }
                    break;

                case "TargetPoint":
                    TargetPoint point = target.GetComponent <TargetPoint>();
                    if (point != null)
                    {
                        if (crop != null)
                        {
                            product = crop.MakeProductFromCrop();
                        }
                        if (product != null)
                        {
                            point.Interact(product, this);
                        }
                    }
                    break;
                }
            }
            else if (hasCan) //for placing the can
            {
                can.GetComponent <Can>().Interact(crop, hasCan, this);
            }
        }
    }