Unity - A计划(一年有效期) 扫二维码继续学习 二维码时效为半小时

(61评价)
价格: 2150.00元
背包问题
M100发起了问答2018-08-07
2
回复
460
浏览

public void OnPointerDown(PointerEventData eventData)
    {
        Debug.Log("点击了一下");
        ItemUI currentItem = transform.GetChild(0).GetComponent<ItemUI>();
        if (transform.childCount > 0)
        {
            if (InventoryManager.Instance.IsPickedItem == true)
            {
                Debug.Log("点击后是否选择了物品:" + InventoryManager.Instance.IsPickedItem);
            }

            if (InventoryManager.Instance.IsPickedItem == false)
            {
                Debug.Log("点击前是否选择了物品:" + InventoryManager.Instance.IsPickedItem);
                if (Input.GetKey(KeyCode.LeftControl))
                {
                    Debug.Log("鼠标上没有东西,按下了ctr");
                    int amountPicked = (currentItem.Amount + 1) / 2;
                    //Debug.Log(amountPicked);
                    InventoryManager.Instance.PickUpItem(currentItem.Item, amountPicked);
                    int amountRemained = currentItem.Amount - amountPicked;
                    if (amountRemained <= 0)
                    {
                        Destroy(currentItem.gameObject);
                    }
                    else
                    {
                        currentItem.SetAmount(amountRemained);
                    }
                }
                else
                {
                    Debug.Log("鼠标上没有东西,没有按下ctr");
                    InventoryManager.Instance.PickUpItem(currentItem.Item, currentItem.Amount);
                    Destroy(currentItem.gameObject);
                }

            }
            else
            {
                Debug.Log("为什么不执行这一段");
                Debug.Log(InventoryManager.Instance.IsPickedItem);
                if (currentItem.Item.ID == InventoryManager.Instance.PickedItem.Item.ID)
                {
                    if (Input.GetKey(KeyCode.LeftControl))
                    {
                        Debug.Log("相同的东西,按下了ctr");
                        if (currentItem.Item.Capacity > currentItem.Amount)//当前物品槽还有容量
                        {
                            currentItem.AddAmount();
                            //InventoryManager.Instance.RemoveOneItem();
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }
        }
    }

老师我上面这段代码,第一次检测鼠标按下的时候可以检测到,为什么检测不到第二次的鼠标按下呢,是不是UI遮挡的问题(吧物品的Raycasy Target勾掉也没有用)

所有回复
  • siki 2018-08-09

    应该都是可以检测到的,是不是你第一次检测到之后,做一些什么处理,然后第二次就检测不到了,是不是鼠标被遮挡了呢 是不是鼠标被弹出层遮挡了呢

    还有-5条回复,点击查看
    你还没有登录,请先登录注册
  • siki 2018-08-09

    也可能是被你拖拽的物体遮挡住了

    还有-5条回复,点击查看
    你还没有登录,请先登录注册
发表回复
你还没有登录,请先 登录或 注册!