Exemple #1
0
    private void UpdateColliders()
    {
        if (InterfaceOpen())
        {
            return;
        }

        for (int i = 0; i < colliders.Count; i++)
        {
            if (colliders[i].gameObject.CompareTag("Egg"))
            {
                if ((Input.GetKeyDown(KeyCode.Space) || (Input.GetMouseButtonDown(1) && colliders[i].gameObject.GetComponent <EggScript>().selected)) &&
                    hotbar.CanAdd(hotbar.eggItem) && !colliders[i].gameObject.GetComponent <EggScript>().isPickedUp)
                {
                    colliders[i].gameObject.GetComponent <EggScript>().isPickedUp = true;
                    colliders[i].gameObject.GetComponent <EggScript>().photonView.RPC("PickUp", PhotonTargets.MasterClient);
                    hotbar.AddItem(Instantiate(hotbar.eggItem));
                }
            }

            else if (colliders[i].gameObject.CompareTag("Raw Chicken"))
            {
                if ((Input.GetKeyDown(KeyCode.Space) || (Input.GetMouseButtonDown(1) && colliders[i].gameObject.GetComponent <RawChickenScript>().selected)) &&
                    hotbar.CanAdd(hotbar.rawChicken) && !colliders[i].gameObject.GetComponent <RawChickenScript>().isPickedUp)
                {
                    hotbar.AddChicken(colliders[i].gameObject.GetComponent <RawChickenScript>().cookedMagnitude);
                    colliders[i].gameObject.GetComponent <RawChickenScript>().isPickedUp = true;
                    colliders[i].gameObject.GetComponent <RawChickenScript>().photonView.RPC("PickUp", PhotonTargets.MasterClient);
                }
            }

            else if (colliders[i].gameObject.CompareTag("Caged Chicken"))
            {
                if ((Input.GetKeyDown(KeyCode.Space) || (Input.GetMouseButtonDown(1) && colliders[i].gameObject.GetComponent <CagedChickenScript>().selected)) &&
                    hotbar.CanAdd(hotbar.rawChicken) && !colliders[i].gameObject.GetComponent <CagedChickenScript>().isPickedUp)
                {
                    colliders[i].gameObject.GetComponent <CagedChickenScript>().isPickedUp = true;
                    colliders[i].gameObject.GetComponent <CagedChickenScript>().photonView.RPC("PickUp", PhotonTargets.MasterClient);
                    hotbar.AddItem(Instantiate(hotbar.cagedChicken));
                }
            }

            else if (colliders[i].gameObject.CompareTag("Axe"))
            {
                if ((Input.GetKeyDown(KeyCode.Space) || (Input.GetMouseButtonDown(1) && colliders[i].gameObject.GetComponent <AxeScript>().selected)) &&
                    hotbar.CanAdd(hotbar.rawChicken) && !colliders[i].gameObject.GetComponent <AxeScript>().isPickedUp)
                {
                    colliders[i].gameObject.GetComponent <AxeScript>().isPickedUp = true;
                    colliders[i].gameObject.GetComponent <AxeScript>().photonView.RPC("PickUp", PhotonTargets.MasterClient);
                    hotbar.AddItem(Instantiate(hotbar.axe));
                }
            }

            else if (colliders[i].gameObject.CompareTag("Feed Bag"))
            {
                if ((Input.GetKeyDown(KeyCode.Space) || (Input.GetMouseButtonDown(1) && colliders[i].gameObject.GetComponent <FeedItemScript>().selected)) &&
                    hotbar.CanAdd(hotbar.feedBag) && !colliders[i].gameObject.GetComponent <FeedItemScript>().isPickedUp)
                {
                    colliders[i].gameObject.GetComponent <FeedItemScript>().isPickedUp = true;
                    colliders[i].gameObject.GetComponent <FeedItemScript>().photonView.RPC("PickUp", PhotonTargets.MasterClient);
                    hotbar.AddItem(Instantiate(hotbar.feedBag));
                }
            }

            else if (colliders[i].gameObject.CompareTag("Chicken") && colliders[i].gameObject.GetComponent <Chicken>().IsSelected() &&
                     CanButcher())
            {
                if (Input.GetMouseButtonDown(0) && !butcher)
                {
                    colliders[i].gameObject.GetComponent <Chicken>().photonView.RPC("PreButcher", PhotonTargets.MasterClient);
                }
            }

            else if (colliders[i].gameObject.CompareTag("Vendor") && colliders[i].gameObject.GetComponent <Vendor>().IsSelected())
            {
                if (Input.GetMouseButtonDown(1))
                {
                    if (transform.position.x < colliders[i].gameObject.transform.position.x && colliders[i].GetComponent <Vendor>().direction == 1)
                    {
                        colliders[i].GetComponent <Vendor>().direction = 0;
                        colliders[i].GetComponent <Vendor>().photonView.RPC("FlipTrue", PhotonTargets.AllBuffered);
                    }
                    else if (transform.position.x > colliders[i].gameObject.transform.position.x && colliders[i].GetComponent <Vendor>().direction == 0)
                    {
                        colliders[i].GetComponent <Vendor>().direction = 1;
                        colliders[i].GetComponent <Vendor>().photonView.RPC("FlipFalse", PhotonTargets.AllBuffered);
                    }

                    uiManager.TalkToVendor();
                }
            }
            else if (colliders[i].gameObject.CompareTag("Oven") && colliders[i].gameObject.GetComponent <Oven>().IsSelected())
            {
                if (Input.GetMouseButtonDown(1))
                {
                    uiManager.OvenMenu.GetComponent <OvenManager>().CurrentOven = colliders[i].gameObject.GetComponent <Oven>();
                    uiManager.ovenVisible = true;
                    FindObjectOfType <AudioManager>().Play("oven");
                }
            }
            else if (colliders[i].gameObject.CompareTag("Fridge") && colliders[i].gameObject.GetComponent <Fridge>().IsSelected())
            {
                if (Input.GetMouseButtonDown(1))
                {
                    uiManager.FridgeMenu.GetComponent <FridgeManager>().CurrentFridge = colliders[i].gameObject.GetComponent <Fridge>();
                    uiManager.fridgeVisible = true;
                    FindObjectOfType <AudioManager>().Play("oven");
                }
            }
            else if (colliders[i].gameObject.CompareTag("Door") && colliders[i].gameObject.GetComponent <Door>().IsSelected())
            {
                if (Input.GetMouseButtonDown(1))
                {
                    colliders[i].gameObject.GetComponent <Door>().photonView.RPC("UpdateState", PhotonTargets.AllBufferedViaServer);
                    if (colliders[i].gameObject.GetComponent <Door>().isOpen)
                    {
                        photonView.RPC("PlayWorldAudio", PhotonTargets.All, "door close");
                    }
                    else
                    {
                        photonView.RPC("PlayWorldAudio", PhotonTargets.All, "door open");
                    }
                }
            }
            else if (colliders[i].gameObject.CompareTag("Switch") && colliders[i].gameObject.GetComponent <LightSwitch>().IsSelected())
            {
                if (Input.GetMouseButtonDown(1))
                {
                    colliders[i].gameObject.GetComponent <LightSwitch>().photonView.RPC("UpdateLight", PhotonTargets.AllBufferedViaServer);
                }
            }
        }
    }