【サバイバルホラーゲームを作りたい。その9】
今回もこちらの動画をやっていきます。
youtu.be
今回は銃の取得と発砲のアニメーションを作ります。
・銃の配置をします。
・銃取得のイベントを作ります。下記スクリプトを追加します。
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class PickUpPistol : MonoBehaviour //EP8追加 テーブル直下のPistolTriggerにアタッチ { public GameObject actionKey; public GameObject actionText; Text actiontext; public InputScript inputScript; public GameObject FakePistol; public GameObject RealPistol; public GameObject GuideArrow; BoxCollider boxCollider; public GameObject ExtraCross; //EP7追加 private void Start() { boxCollider = GetComponent<BoxCollider>(); actiontext = actionText.GetComponent<Text>(); } private void OnTriggerEnter(Collider other) { //コライダーにプレイヤーが当たった場合 if (other.tag == "Player") { // Debug.Log("hit"); //キー押下~のメッセージを表示 actionKey.SetActive(true); actionText.SetActive(true); actiontext.text = "Pick Up Pistol"; ExtraCross.SetActive(true); //EP7追加 } } private void OnTriggerStay(Collider other) { if (other.tag == "Player") { //ドアオープン if (inputScript.getInputActions()) { actionKey.SetActive(false); actionText.SetActive(false); boxCollider.enabled = false; ExtraCross.SetActive(false); FakePistol.SetActive(false); RealPistol.SetActive(true); GuideArrow.SetActive(false); } } } ////コライダーからプレイヤーが離れた場合 private void OnTriggerExit(Collider other) { actionKey.SetActive(false); actionText.SetActive(false); ExtraCross.SetActive(false); //EP7追加 } }
・発砲のアニメーションを作ります。
・ステージを広げていきます。
今回は以上です。