示例#1
0
    // function to lift object
    void liftObjects()
    {

        // raycast to get the object in front of the player
        RaycastHit raycastHit;
        bool hit = Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out raycastHit);

        // check if the object is liftable
        if (hit && raycastHit.transform.gameObject.tag == "liftable")
        {

            // set the racast gameObject to a variable and get the cubeController
            liftObject = raycastHit.transform.gameObject;
            liftObjectScript = liftObject.GetComponent<CubeController>();

            // check if the current gravity of the player is the same as the direction
            if (liftObjectScript.gravityDirection == gravityOnNormals.currentDirection)
            {

                // set the script to not use gravity
                liftObjectScript.useGravity = false;

                // set objectPickedUp to true so the player script knows that an object is picked up 
                objectPickedUp = true;

                // call a fuction in the object's script to be picked up
                liftObjectScript.pickUpObject(this);
            }
        }
    }