Пример #1
0
    //拾取以摄像机为中心,半径为radius的区域内的物品。并把物品加入背包
    void PickSurroundingItems()
    {
        Collider[] colliders = Physics.OverlapSphere(tr.position, radius, mask.value);
        Debug.Log("范围内选中 " + colliders.Length);
        List <ItemInfo> itemList = new List <ItemInfo>();

        for (int i = 0; i < colliders.Length; i++)
        {
            Collider   ht      = colliders[i];
            GameObject gameobj = ht.gameObject;
            ToolItem   item    = gameobj.GetComponent <ToolItem>();
            if (item != null)
            {//把物品加入背包
                ItemInfo itemInfo = item.OnGetItemInfo();
                itemList.Add(itemInfo);
            }
        }
    }