示例#1
0
    // Update is called once per frame

    void Update()
    {
        if (holding == false && transform.childCount > 0)
        {
            //Debug.Log("(R)Your hand should be empty, but you're still holding something. Letting go now.");
            //Debug.Log("That child is " + transform.GetChild(0));
            transform.GetChild(0).transform.parent = GameObject.Find("world").transform;
        }

        //calculate reach into the z axis
        float xChunk = (handR.getPosX() - elbowR.getPosX());
        float yChunk = (handR.getPosY() - elbowR.getPosY());

        measuredArm = xChunk * xChunk + yChunk * yChunk;
        //you should technically take the square root of this, but mirroring reality exactly is lame
        reachDepth = ARM_LENGTH * ARM_LENGTH - measuredArm * measuredArm;
        //and update the position
        //only kind of a hardcoded nightmare
        gameObject.transform.localPosition = new Vector3(handR.getPosX() * multiplier, handR.getPosY() * multiplier, (reachDepth * multiplier * 100) - 40);

        //grab a book
        if (handR.isRightHandClosed || Input.GetKeyDown("p"))
        {
            if (selectBook.getHeldObject() != null)
            {
                if (selectBook.getHeldObject().tag == "closedBook")
                {
                    selectBook.getHeldObject().transform.SetParent(this.gameObject.transform);
                    holding = true;                //we need to check that it worked before we do this
                }
            }
        }
        //let go
        if ((!handR.isRightHandClosed && holding == true) || (Input.GetKeyDown("l") && holding == true))
        {
            holding = false;
            //if its a hand, keep it on your body
            if (selectBook.getHeldObject() != null)
            {
                if (selectBook.getHeldObject().tag == "hand")
                {
                    selectBook.getHeldObject().transform.parent = GameObject.Find("playerBody").transform;
                }
                else         //this part isn't working                                                                                   !
                {
                    selectBook.getHeldObject().transform.parent = GameObject.Find("world").transform;
                }
            }
        }
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        //Checks if you're holding extra objects, and lets them go if you are
        if (holding == false && transform.childCount > 0)
        {
            transform.GetChild(0).transform.parent = GameObject.Find("world").transform;
        }
        //are you indicating that you want to do something with one of the open books?
        //currently hardcoded into 4 quadrants
        //selectedBook is a pretty bad name for this
        if (handL.isLeftHandClosed)
        {
            if (handL.getPosX() < 0)
            {
                if (handL.getPosY() < 0)
                {
                    selectBook.selectedBook = 0;
                }
                else
                {
                    selectBook.selectedBook = 2;
                }
            }
            else
            {
                if (handL.getPosY() < 0)
                {
                    selectBook.selectedBook = 1;
                }
                else
                {
                    selectBook.selectedBook = 3;
                }
            }
        }

        //calculate reach into the z axis
        float xChunk = (handL.getEasedPosX() - elbowL.getEasedPosX());
        float yChunk = (handL.getEasedPosY() - elbowL.getEasedPosY());

        measuredArm = xChunk * xChunk + yChunk * yChunk;
        //you should technically take the square root of this, but mirroring reality exactly is lame
        reachDepth = ARM_LENGTH * ARM_LENGTH - measuredArm * measuredArm;
        //and update the position
        //only kind of a hardcoded nightmare
        gameObject.transform.localPosition = new Vector3(handL.getEasedPosX() * multiplier, handL.getEasedPosY() * multiplier, (reachDepth * multiplier * 100) - 40);

        //grab/hold book
        if (handL.isLeftHandClosed && holding == false || Input.GetKeyDown("o") && holding == false)
        {
            if (selectBook.getHeldObject().tag == "closedBook")
            {
                selectBook.getHeldObject().transform.SetParent(this.gameObject.transform);
                holding = true;
            }
        }
        //let go
        if (Input.GetKeyDown("z") && holding == true)
        {
            holding = false;
            //if its a hand, keep it on your body
            if (selectBook.getHeldObject().tag == "hand")
            {
                selectBook.getHeldObject().transform.parent = GameObject.Find("playerBody").transform;
            }
            else
            {
                selectBook.getHeldObject().transform.parent = GameObject.Find("world").transform;
            }
        }
    }