LoginSignup
1
1

More than 5 years have passed since last update.

押すと文字が切り替わるボタン

Last updated at Posted at 2015-04-01

ぽちぽち押すと、文字が切り替わっていくボタン実装
ソートボタンとかの、強い順→弱い順→新しい順→… みたいなやつです

using System.Collections.Generic;
public class ToggleText : MonoBehaviour {
    public List<string> StateTexts = new List<string>();
    public int State = 0;
    public UILabel LabelObj =null;

    void Start () {
        SetText(State);
    }

    public void Increment(){
        SetText(State + 1);
    }

    public void SetText(int _idx){
        if( _idx >= StateTexts.Count ){
            _idx = 0;
        }
        if( LabelObj != null ){
            LabelObj.text = StateTexts[_idx];
        }
        State = _idx;
    }
}

こんな感じでインスペクタで設定可能。
スクリーンショット 2015-04-01 10.34.39.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1