Beispiel #1
0
    void CollectItem()
    {
        if (Input.GetMouseButtonDown(0))
        { //left mouse button
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                if (hit.collider.tag == "Pickable Item")
                {
                    ItemButton itb  = hit.collider.gameObject.GetComponent <ItemButton>();
                    string     name = itb.GetItemName();
                    if (inventory == null)
                    {
                        print("no inventory");
                    }
                    else
                    {
                        print("there is an inventory");
                    }
                    inventory.AddItem(itb.GetItemID());
                    Destroy(hit.collider.gameObject);
                    print("Added " + name + " to inventory");
                }
            }
        }//if mousebutton down end
    }