Пример #1
0
 void UpdateInventoryCanvas(Canvas inventoryCanvas)
 {
     selectedItem.transform.SetParent(inventoryCanvas.transform);
     selectedItem.GetComponent <Text>().color = Color.black;
     selectedItem         = null;
     itemTitle.text       = "";
     itemDescription.text = "";
     itemPrice.text       = "";
 }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        //Check if the left Mouse button is clicked
        if (Input.GetKey(KeyCode.Mouse0))
        {
            //Set up the new Pointer Event
            m_PointerEventData = new PointerEventData(m_EventSystem);
            //Set the Pointer Event Position to that of the mouse position
            m_PointerEventData.position = Input.mousePosition;

            //Create a list of Raycast Results
            List <RaycastResult> results = new List <RaycastResult>();
            EventSystem.current.RaycastAll(m_PointerEventData, results);

            foreach (RaycastResult result in results)
            {
                shopItem trySelectItem = result.gameObject.GetComponent <shopItem>();

                if (trySelectItem)
                {
                    if (selectedItem)
                    {
                        selectedItem.GetComponent <Text>().color = Color.black;
                    }

                    selectedItem = trySelectItem;
                    selectedItem.GetComponent <Text>().color = Color.red;
                    itemTitle.text       = selectedItem.item.title;
                    itemDescription.text = selectedItem.item.description;
                    itemPrice.text       = selectedItem.item.price.ToString();
                }
            }
        }
    }