Exemplo n.º 1
0
    IEnumerator Grab()
    {
        busy = true;                                                // prevent multiple grabbing
        _StateManager.ChangeUserState(StateManager.UserState.busy); // prevent further action when fruit is in the air
        grabbedStack = activeObject;

        print(activeObject + " costs $" + activeObject.GetComponent <IFruit>().price);

        GameObject grabbed = Instantiate(activeObject.GetComponent <IFruit>().fruitPrefab, activeObject.transform.position, Quaternion.Euler(new Vector3(0, 0, 0))); // create a copy of the selected fruit. ie. A single watermelon from the pile of watermelon

        _ObjectState.Held(grabbed);                                                                                                                                  // Turn off the fruits gravity, important or else the fruit will build up velocity as it travels and will unnaturally fall at the end of the moition
        _ObjectManager.AddToOffShelf(grabbed);                                                                                                                       // Add object to offshelf dictionary. It can now be quiries from _ObjectManager.heldObject

        GUI(activeObject);

        // Rotate and move fruit to controller
        LeanTween.rotate(grabbed, new Vector3(90, 0, 0), 1.5f).setEase(LeanTweenType.easeOutQuad);
        LeanTween.move(grabbed, controller.transform.position + (controller.transform.forward * 0.1f) + new Vector3(-0.2f, 0, 0), 1.5f).setEase(LeanTweenType.easeOutQuad);

        grabbed.GetComponent <Collider>().enabled = false; // Disable the fruits collider for extra secruity
        yield return(new WaitForSeconds(0.1f));

        _UIController.On(); // turn the fruits information screen on, change the first WaitforSeconds to increase or decrease delay.
                            // Both should always sum to 1.5f as that is the time it takes for the object to arrive at the controller.
        yield return(new WaitForSeconds(1.4f));


        heldObject = _ObjectManager.WhatsOffShelf().Key;

        holding = true;
        busy    = false;

        _StateManager.ChangeUserState(StateManager.UserState.examining); // Set State to examining
    }