【サバイバルホラーゲームを作りたい。その14】
今回もこちらの動画をやっていきます。
youtu.be
今回はゲームオーバシーンを実装します。
・ゾンビ攻撃時の音を実装します。
public class ZombieAi : MonoBehaviour //EP13追加 ゾンビにアタッチ { (省略) public AudioSource zombieAttackSound; //EP14追加 // Update is called once per frame void Update() { transform.LookAt(thePlayer.transform); if (!attackTrigger && walkOn) { enemySpeed = 0.01f; //歩行アニメーション EnemyAnimator.Play("Z_Walk"); //ターゲット方向に移動 transform.position = Vector3.MoveTowards(transform.position, thePlayer.transform.position, enemySpeed); StartCoroutine(walk()); } if (attackTrigger && !isAttacking) { enemySpeed = 0; //攻撃アニメーション EnemyAnimator.Play("Z_Attack"); zombieAttackSound.Play(); //EP14追加 StartCoroutine(InflactDajmage()); } } }
・ゲームオーバーシーンを新たに作成します。
・プレイヤーのHPが0以下の場合、ゲームオーバーシーンに遷移するようにします。
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; //EP14追加 public class GlobalHealth : MonoBehaviour //EP13追加 プレイヤーにアタッチ { public static int currentHealth = 20; public int internalHealth; // Update is called once per frame void Update() { internalHealth = currentHealth; if (currentHealth <= 0) //EP14追加 { SceneManager.LoadScene(1); } } }
・弾薬箱を設置します。
今回は以上です。