zoukankan      html  css  js  c++  java
  • Unity3d

    上期工程实现了角色状态栏的显示,现在开始实现角色的加点功能。

    需求:当角色存在point_Remain > 0 时,可以分配给伤害、防御及速度中的任意一个。

    思路:

    在PlayerStatus脚本中更新关于point_Remain -1的方法,并且在按键响应的脚本中调用该方法,并使对应的属性值加1。

    这样就实现了,无论增加哪个属性值,都会通过PlayerStatus中的脚本进行实现。

    简直完美。

    脚本如下:

    Class PlayerStatus

    {

        public bool GetPoint(int i = 1)

        {

            if( point_Remain >= i )

            {

                point_Remain -= i;

                return true;

            }

            return false;

        }

    }

    Class Status

    {

        public void OnAttack_PlusClick( )

        {

            bool sucess = playerstatus.GetPoint( );

            if(sucess)

            {

                playerstatus.attack_plus ++;

                Show();

            }

        }

        public void OnDef_PlusClick( )

        {

            bool sucess = playerstatus.GetPoint( );

            if(sucess)

            {

                playerstatus.def_plus ++;

                Show();

            }

        }

        public void OnSpeed_PlusClick( )

        {

            bool sucess = playerstatus.GetPoint( );

            if(sucess)

            {

                playerstatus.speed_plus ++;

                Show();

            }

        }

    }

    将上述方法注册到加号按钮就可以了。

  • 相关阅读:
    未能正确加载“Microsoft.VisualStudio.Editor.Implementation.EditorPackage”包
    Only one instance of a ScriptManager can be added to the page.
    springboot SSM
    spring mvc 请求转发和重定向
    Spring Boot 配置 Swagger2 接口文档引擎
    solr
    jQuery
    反向代理负载均衡-Nginx
    mybatis二级缓存
    Vue的路由
  • 原文地址:https://www.cnblogs.com/yanbenxin/p/5850964.html
Copyright © 2011-2022 走看看