Exemple #1
0
    public void pickUpFunc()
    {
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            int x = Screen.width / 2;
            int y = Screen.height / 2;

            Ray        rayCheck = mainCamCamObj.ScreenPointToRay(new Vector3(x, y));
            RaycastHit hitCheck;
            if (Physics.Raycast(rayCheck, out hitCheck))
            {
                PickupableScript p = hitCheck.collider.GetComponent <PickupableScript> ();
                if (p != null)
                {
                    carrying              = true;
                    carriedObj            = p.gameObject;
                    cObjRBody             = p.gameObject.GetComponent <Rigidbody> ();
                    cObjRBody.useGravity  = false;
                    cObjRBody.isKinematic = false;
                    //carriedObj.tag = "box";

                    /* This is where the call goes out to check if the object picked up has a
                     * dialogReader script attached to it. If it does, it will return the readlines
                     * functions and the item description will appear.
                     * If it doesn't, it will null out but not cause the game to crash.
                     * *figured it was necessary to implement that in case we forget an object at
                     * any point. */

                    dialogReader itemdescript = carriedObj.gameObject.GetComponent <dialogReader> ();
                    if (itemdescript != null)
                    {
                        itemdescript.readlines();
                        BT.objectcount++;
                    }
                    else
                    {
                        Debug.Log("null");
                    }
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Inventory.Instance.HasItem() && Input.GetMouseButtonDown(0))
        {
            GameObject itemDropped = Inventory.Instance.RemoveCurrItem();
            itemDropped.transform.position = Camera.main.transform.position;
            itemDropped.GetComponent <Rigidbody>()?.AddForce(Camera.main.transform.forward * _throwPower, ForceMode.Impulse);
        }
        else if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out RaycastHit hit, _lookDistance))
        {
            PickupableScript pickup = hit.collider?.GetComponent <PickupableScript>();
            if (pickup)
            {
                pickup.LookAt();

                if (Input.GetMouseButtonDown(0) && !Inventory.Instance.HasItem())
                {
                    pickup.PickUp(transform);
                }
            }
        }
    }