zoukankan      html  css  js  c++  java
  • Unity3d

    上期工程实现了装备的穿上功能,但是还有些不完善,我们必须进行进一步完善。

    需要完善的内容主要有2个:

    ①如果穿带前该栏有装备,那么需要将原装备退回至背包内;

    ②成功穿戴装备后,需要使背包内的相应装备数量-1,如果数量为0了,那么删除该格内的物品。

    脚本如下:

    实现功能①,只需要在Class EquipmentUI中的Dress方法中检测格子内是否有物品的条件的代码块更新为:

    if(item != null)

    {

        Inventory._instance.GetId(item.id);

        item.SetInfo(info);

    }

    这样就实现了将原装备放回背包的功能。(其实并不是放回,而是重新建立了一个物品镜像而已)

    实现功能②,需要在InventoryItem的方法中进行更新:

    Class InventoryItem

    {

        void Update( )

        {

            if(isHover)

            {

                bool success = EquipmentUI._instance.Dress(id);

                if(success)

                {

                    this.tranform.parent.GetCompnent<InventoryItemGrid>().MinusNumber();//这个方法后续来构建

                }

            }

        }

    }

    现在开始构建计数减少的方法

    Class InventoryItemGrid

    {

        public bool MinusNumber(int num = 1)

        {

            if(this.num >= num)

            {

                this.num -= num;

                numberLaber.text = this.num;

                if(this.num == 0)

                 {

                     ClearInfo();

                     GameObject.Destory(this.GetCompnentInChild<InventoryItem>().gameObject);

                 }

                return true;

            }

                return false;

        }

    }

    这样就构建了装备的穿戴系统。

  • 相关阅读:
    避免Node.js中回调地狱
    XSS和CSRF攻击
    浅析SPDY
    移动端的图片优化
    js中的事件委托技术
    js的5种继承方式——前端面试
    深入理解前端跨域问题的解决方案——前端面试
    javascript中“use strict”的好处和坏处
    Http请求中POST与GET的区别——前端面试
    滚动条离底部的距离小于某个值
  • 原文地址:https://www.cnblogs.com/yanbenxin/p/5875643.html
Copyright © 2011-2022 走看看