阅读 227

Unity 游戏黑暗之光笔记

Unity 游戏黑暗之光笔记

第六章 状态系统的实现

1.UI设计

 

 

2.控制显示

  • 挂载Status脚本

复制代码

 public static Status _instance;    private TweenPosition tween;    private bool isShow = false;    private void Awake()
    {
        _instance = this;
        tween = this.GetComponent<TweenPosition>();
    }   public void TransformState()
    {        if(isShow==false)
        {
            tween.PlayForward();
            isShow = true;
        }        else
        {
            tween.PlayReverse();
            isShow = false;
        }
    }

复制代码

3.控制属性的变化

  • 添加脚本控制

复制代码

public static Status _instance;    private TweenPosition tween;    private bool isShow = false;    private UILabel attackLabel;    private UILabel defLabel;    private UILabel speedLabel;    private UILabel pointRemainLabel;    private UILabel summaryLabel;    private GameObject attackButtonGo;    private GameObject defButtonGo;    private GameObject speedButtonGo;    private PlayerStatus ps;    void Awake()
    {
        _instance = this;
        tween = this.GetComponent<TweenPosition>();

        attackLabel = transform.Find("attack").GetComponent<UILabel>();
        defLabel = transform.Find("def").GetComponent<UILabel>();
        speedLabel = transform.Find("speed").GetComponent<UILabel>();
        pointRemainLabel = transform.Find("point_remain").GetComponent<UILabel>();
        summaryLabel = transform.Find("summary").GetComponent<UILabel>();

        attackButtonGo = transform.Find("attack_plusbutton").gameObject;
        defButtonGo = transform.Find("def_plusbutton").gameObject;
        speedButtonGo = transform.Find("speed_plusbutton").gameObject;
        ps = GameObject.FindGameObjectWithTag(Tags.player).GetComponent<PlayerStatus>();

    }    public void TransformState()
    {        if (isShow == false)
        {
            UpdateShow();
            tween.gameObject.SetActive(true);
            tween.PlayForward();
            isShow = true;
        }        else
        {
            tween.PlayReverse();
            isShow = false;
        }
    }    void UpdateShow()
    {// 更新显示 根据ps playerstatus的属性值,去更新显示
        attackLabel.text = ps.attack + " + " + ps.attack_plus;
        defLabel.text = ps.def + " + " + ps.def_plus;
        speedLabel.text = ps.speed + " + " + ps.speed_plus;

        pointRemainLabel.text = ps.point_remain.ToString();

        summaryLabel.text = "伤害:" + (ps.attack + ps.attack_plus)            + "  " + "防御:" + (ps.def + ps.def_plus)            + "  " + "速度:" + (ps.speed + ps.speed_plus);        if (ps.point_remain > 0)
        {
            attackButtonGo.SetActive(true);
            defButtonGo.SetActive(true);
            speedButtonGo.SetActive(true);
        }        else
        {
            attackButtonGo.SetActive(false);
            defButtonGo.SetActive(false);
            speedButtonGo.SetActive(false);
        }

复制代码

在transformStatus方法中注意加上 tween.gameObject.SetActive(true);才会使得动画正确播放

  • 添加点数增加的控制方法

复制代码

public void OnAttackPlusClick()
    {        bool success = ps.GetPoint();        if (success)
        {
            ps.attack_plus++;
            UpdateShow();
        }
    }    public void OnDefPlusClick()
    {        bool success = ps.GetPoint();        if (success)
        {
            ps.def_plus++;
            UpdateShow();
        }
    }    public void OnSpeedPlusClick()
    {        bool success = ps.GetPoint();        if (success)
        {
            ps.speed_plus++;
            UpdateShow();
        }
    }

复制代码

游戏黑暗之光的开发笔记写到这里也第六章了,一个游戏也快完结了

来源:https://www.cnblogs.com/heyu123/p/14808915.html

服务器评测 http://www.cncsto.com/ 

服务器测评 http://www.cncsto.com/ 


文章分类
后端
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐