zoukankan      html  css  js  c++  java
  • Unity3d

    前期工程已经构建了背包、格子、物品三者的关系。简单概括,就是背包管理格子,格子管理(生成、消除)物品,物品根据id或icon_name变更sprite。现在开始进行模拟物品的拾取功能。对Inventory脚本进行添加:

    Class Inventory

    {

        public GameObject InventoryItem;

        void Update( )

        {

            if(Inpt.GetKeyDown(keycode.x))

            {

                 GetId(Randam.Range(1001,1004));     

            }

        }

        public void  GetId(int id)

        {

            Inventory_grid grid = null;

            foreach( var temp in GridList )

            {

                if(temp.id == id)

                {

                     grid = temp;

                     break;

                 }

            }

            if( grid != null )

            {

                 grid.PlusNumber( );

            }

            else

            {

                foreach( var temp in GridLsit )

                {

                    if(temp.id == 0)

                    {

                         grid = temp;

                         break;

                    }

                }

                if(grid != null)

                {

                    GameObject itemGo = NGUITools.AddChlid(grid,inventoryitem);

                    itemGo.transform.localPosition = Vector3.zero;

                    grid.SetId(id);

                }

            }

        }

    }

    以上就实现了向背包格子中添加游戏物品。

  • 相关阅读:
    HDU 2955 Robberies(01背包)
    HDU 2602 Bone Collector(01背包)
    HUST 1352 Repetitions of Substrings(字符串)
    HUST 1358 Uiwurerirexb jeqvad(模拟解密)
    HUST 1404 Hamming Distance(字符串)
    HDU 4520 小Q系列故事――最佳裁判(STL)
    HDU 2058 The sum problem(枚举)
    【破解】修改程序版权、添加弹窗
    HDU 1407 测试你是否和LTC水平一样高(枚举)
    HDU 1050 Moving Tables(贪心)
  • 原文地址:https://www.cnblogs.com/yanbenxin/p/5835708.html
Copyright © 2011-2022 走看看