ちょこ

学生です。メモっぽく。

Unity 2Dゲーム開発日記 10日目 ~ステータス~

データの保存

PlayerPrefsっていう便利なものがありました。
Unity - Scripting API: PlayerPrefs

PlayerPrefs.SetInt("key", value);
みたいに型を指定してSetしたりGetしたりできる!
PlayerPrefs.DeleteKey("key");
で削除もできる!
これでステータス保存して、攻撃力の変更ができるようになりました。

ちょっと迷ったのが、

StartとAwake関数の違い


UnityでのAwakeとStartとUpdateで微妙にはまったところ - Guinea Pig

Awake → Start → Update → Update
みたいなのだと思っている。

各Script毎にGetIntするのか、1つのScriptからstaticとかで持ってきた方がいいのか

自分の中の結論では、各ScriptごとにGetする。間違い防ぎやすいのかなと思った。

OnGUIでグルーピング

void OnGUI () {
    // Make a group on the center of the screen
    GUI.BeginGroup (new Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100));
    // All rectangles are now adjusted to the group. (0,0) is the topleft corner of the group.

    // We'll make a box so you can see where the group is on-screen.
    GUI.Box (new Rect (0,0,100,100), "Group is here");
    GUI.Button (new Rect (10,40,80,30), "Click me");

    // End the group we started above. This is very important to remember!
    GUI.EndGroup ();
}

公式ドキュメントより。

GUI使って簡単にステータス画面作った。
めっちゃださい。

やったこと

  • Status画面の作成
  • ステータスの実装

やりたいこと

  • ゲーム終了画面を作る。
  • HPバー作る

とか。