Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (!GameManager.Instance.gameOver)
        {
            if (canInteract && interactable != null && Input.GetKeyDown(KeyCode.Q))
            {
                // do the interaction shit here
                if (interactable.tag == "Item")
                {
                    {
                        if (interactable.name.Contains("Can"))
                        {
                            prevInteractable.GetComponent <Factory>().TakeItem();
                            interactable = prevInteractable;
                            CanvasManager.Instance.ShowBottomLeftText("Gotta go fast!");
                            interactable.GetComponent <Factory>().lastTime = GameManager.Instance.updateTime;
                            isOily = true;
                            WorldController.Instance.speed = 75f;
                            StartCoroutine("SpeedUpCountDown");
                        }
                        else if (inventory[MAX_ITEMS_HELD - 1] == Statics.Items.NONE)
                        {
                            for (int i = 0; i < MAX_ITEMS_HELD; i++)
                            {
                                if (inventory[i] == Statics.Items.NONE)
                                {
                                    switch (interactable.name.Substring(0, 3))
                                    {
                                    case "Gea":
                                        inventory[i]   = Statics.Items.GEAR;
                                        actualItems[i] = Instantiate(ItemManager.Instance.gear);
                                        break;

                                    case "Spr":
                                        inventory[i]   = Statics.Items.SPRING;
                                        actualItems[i] = Instantiate(ItemManager.Instance.spring);
                                        break;

                                    case "Scr":
                                        inventory[i]   = Statics.Items.SCREW;
                                        actualItems[i] = Instantiate(ItemManager.Instance.screw);
                                        break;
                                    }
                                    if (actualItems[i] != null)
                                    {
                                        prevInteractable.GetComponent <Factory>().TakeItem();
                                        interactable = prevInteractable;
                                        CanvasManager.Instance.ShowBottomLeftText("Obtained " + interactable.GetComponent <Factory>().item);
                                        interactable.GetComponent <Factory>().lastTime = GameManager.Instance.updateTime;
                                        actualItems[i].transform.parent   = spawnPoints[i].transform;
                                        actualItems[i].transform.position = spawnPoints[i].transform.position;
                                        actualItems[i].GetComponent <BoxCollider>().enabled             = false;
                                        actualItems[i].GetComponent <SpriteRenderer>().sortingLayerName = "HeldItems";
                                        actualItems[i].GetComponent <SpriteRenderer>().sortingOrder     = i;
                                        numItemsHeld += 1;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
                else if (interactable.tag == "Component" && currComp.isBroken)
                {
                    currComp.repair();
                }
                else if (interactable.tag == "MainSpring")
                {
                    if (interactable.GetComponent <Gearbox>().isBroken())
                    {
                        currComp.repair();
                    }
                    else
                    {
                        interactable.GetComponent <Gearbox>().wind();
                    }
                }
                else if (interactable.tag == "Recycling" && inventory[0] != Statics.Items.NONE)
                {
                    for (int i = 0; i < MAX_ITEMS_HELD; i++)
                    {
                        inventory[i] = Statics.Items.NONE;
                        Destroy(actualItems[i]);
                    }
                    numItemsHeld = 0;
                }
                nonOilySpeed = 30 - 5 * numItemsHeld;
            }
        }
        if (!isOily)
        {
            WorldController.Instance.speed = nonOilySpeed;
        }
    }