カロリーメイトください

Barbaroi Ware(バルバロイ・ウェア)という名前でアプリ開発してます

『Unity5の教科書』「Chapter8 レベルデザイン」 学習記録3

序文

「Unity5の教科書」学習11日目、いや昨日もちょっとやったので12日目。

…終わった!

GitHub

github.com

進捗

(学習時間:2時間)

コード実装部分(一部)

\AppleCatch\Assets\GameDirector.cs

using UnityEngine;
using UnityEngine.UI;

public class GameDirector : MonoBehaviour
{
  // タイマーUI
  GameObject timerText;
  // ポイントUI
  GameObject pointText;
  // 残り時間
  float time = 30.0f;
  // ポイント
  int point = 0;
  // アイテムジェネレーター
  GameObject generator;

  // りんごを受け取ったら+100
  public void GetApple()
  {
    this.point += 100;
  }

  // 爆弾を受け取ったら得点半分
  public void GetBomb()
  {
    this.point /= 2;
  }

  void Start()
  {
    this.timerText = GameObject.Find("Time");
    this.pointText = GameObject.Find("Point");
    this.generator = GameObject.Find("ItemGenerator");
  }

  void Update()
  {
    // 画面更新間隔を減算して残り時間を算出
    this.time -= Time.deltaTime;

    // 良い感じの難易度に設定する
    // 第一引数 : アイテム落下間隔
    // 第二引数 : 落下速度
    // 第三引数 : 爆弾が落ちてくる割合
    if (this.time < 0)
    {
      this.time = 0;
      this.generator.GetComponent<ItemGenerator>().SetParameter(float.MaxValue, 0, 0);
    }
    else if (0 <= this.time && this.time < 5)
    {
      this.generator.GetComponent<ItemGenerator>().SetParameter(0.7f, -0.04f, 3);
    }
    else if (5 <= this.time && this.time < 12)
    {
      this.generator.GetComponent<ItemGenerator>().SetParameter(0.5f, -0.05f, 6);
    }
    else if (10 <= this.time && this.time < 23)
    {
      this.generator.GetComponent<ItemGenerator>().SetParameter(0.8f, -0.04f, 4);
    }
    else if (20 <= this.time && this.time < 30)
    {
      this.generator.GetComponent<ItemGenerator>().SetParameter(1.0f, -0.03f, 2);
    }

    // UI表示
    this.timerText.GetComponent<Text>().text = this.time.ToString("F1");
    this.pointText.GetComponent<Text>().text = this.point.ToString() + " point";
  }
}
  • その他実装部分

github.com

実行結果

www.youtube.com 割と楽しい(笑)

感想

りんごキャッチゲーム完成。
制限時間30秒でりんごをキャッチすると+100、爆弾をキャッチすると得点が1/2になる。

あれ、得点のUIが画面外にはみ出てるからちょっと設定間違ってるかも(直す気はない)。

というわけであっという間に「Unity5の教科書」読了。
明日いつものようにまとめて感想を書く予定ですが、終始「とりあえず作ってみる」という点で趣旨が一貫していて、レベルはともかく良い本だなと思いました。
やっぱどっちつかずなのはダメだよ。
プログラム未経験者でも実務ができるレベルまで育て上げます!とかさ(どことは言わない)。

カロリーメイトください。

BGM

magic number / KICK THE CAN CREW

www.youtube.com