カロリーメイトください

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

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

序文

「Unity5の教科書」学習10日目。

本命のプロジェクトが絶賛遅れてるので少しだけ。

GitHub

github.com

進捗

(学習時間:1時間)

コード実装部分(一部)

using UnityEngine;

public class BasketController : MonoBehaviour {
  // りんごゲットSE
  public AudioClip appleSE;
  // 爆弾SE
  public AudioClip bombSE;
  AudioSource aud;

  private void Start()
  {
    this.aud = GetComponent<AudioSource>();
  }

  private void OnTriggerEnter(Collider other)
  {    
    if(other.gameObject.tag == "Apple")
    {
      this.aud.PlayOneShot(this.appleSE);
    }
    else
    {
      this.aud.PlayOneShot(this.bombSE);
    }
    Destroy(other.gameObject);
  }

  void Update () {
    if (Input.GetMouseButton(0))
    {
      // カメラ位置からクリック座標へ向いたRayオブジェクトを取得
      Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
      RaycastHit hit;
      // Rayオブジェクトが(ステージに)遮られているかを判定
      if(Physics.Raycast(ray, out hit, Mathf.Infinity))
      {
        // バスケットを移動すべき位置を取得して移動させる
        float x = Mathf.RoundToInt(hit.point.x);
        float z = Mathf.RoundToInt(hit.point.z);
        transform.position = new Vector3(x, 0.0f, z);
      }
    }       
  }
}
  • その他実装部分

github.com

実行結果

www.youtube.com

感想

りんごと爆弾が落ちてきて、バスケットで受け取った時にSEを鳴らすように改良。

大体今までやったことと同じ内容なので特に感想はないけど、相変わらず説明が丁寧だ。
たとえば、りんごと爆弾の処理なんかほとんど同じなのに、それぞれ別々に説明してくれたりする。
人によってはいらいらする人もいるかもしれないけど。

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

BGM

Say "I Gotta Believe!" / De La Soul Feat. DOUBLE

www.youtube.com