示例#1
0
    //Mostly temp
    void Update()
    {
        if (Input.GetKey(KeyCode.Mouse1))
        {
            if (items[SelectedSlot] as UsableItem != null)
            {
                UsableItem activeItem = (UsableItem)items[SelectedSlot];
                if (activeItem.Activate())
                {
                    if (activeItem.RemoveAfterUse)
                    {
                        RemoveItem(SelectedSlot);
                    }
                }
            }
            else
            {
                //raytest
                //All this has to move to like player or something
                Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit2D hit = Physics2D.GetRayIntersection(ray);
                if (hit)
                {
                    if (hit.collider != null)
                    {
                        GameObject obj = hit.transform.gameObject;
                        if (obj.tag == "Clickable")
                        {
                            obj.GetComponent <Plant>().OnCast();
                            //Need a series of classes for objects in world, with on clicked() etc.
                        }
                    }
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            inventoryPanel.SetActive(!inventoryPanel.activeSelf);
            tooltip.Deactivate();
        }

        if (Input.GetKeyDown(KeyCode.Q))
        {
            //Drop selected item
            DropItem(SelectedSlot);
        }

        if (Input.GetKeyDown(KeyCode.P))
        {
            updateSelectedSlot(SelectedSlot + 1);
        }
        if (Input.GetKeyDown(KeyCode.O))
        {
            updateSelectedSlot(SelectedSlot - 1);
        }

        //Input for selected slot in toolbar
        items[SelectedSlot].WhileSelected();
    }