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();        }    }

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