【サバイバルホラーゲームを作りたい。その40】
今回はパズル要素を完成させます。
具体的には左右パズルを取得し特定の位置に配置すると、壁がせり上がる仕組みを作ります。
youtu.be
・完成形パズルを置く場所を作ります。
・壁がせり上がるアニメーションを作ります。
・完成形パズルを配置すると壁がせり上がる仕組みを実装します。
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class RionPlacement : MonoBehaviour //EP40追加 RionPlacement直下のColliderObjにアタッチ { public GameObject actionKey; public GameObject actionText; Text actiontext; public InputScript inputScript; public GameObject ExtraCross; public GlobalInventory globalInventory; public GameObject RionObj; public Animator RealWallAnim; BoxCollider boxCollider; private void Start() { actiontext = actionText.GetComponent<Text>(); boxCollider = gameObject.GetComponent<BoxCollider>(); } private void OnTriggerEnter(Collider other) { //コライダーにプレイヤーが当たった場合 if (other.tag == "Player") { // Debug.Log("hit"); //キー押下~のメッセージを表示 actionKey.SetActive(true); actionText.SetActive(true); actiontext.text = "Place Rion Pieces"; ExtraCross.SetActive(true); } } private void OnTriggerStay(Collider other) { if (inputScript.getInputActions()) { //RionObjを所有している場合、壁が上がる if (globalInventory.getLeftRionObj() && globalInventory.getRightRionObj()) { boxCollider.enabled = false; actionKey.SetActive(false); actionText.SetActive(false); ExtraCross.SetActive(false); RionObj.SetActive(true); RealWallAnim.Play("RealWallRise"); } //RionObjを所有していない場合、何もおこらない else { actiontext.text = "No Item"; } } } //コライダーからプレイヤーが離れた場合 private void OnTriggerExit(Collider other) { actionKey.SetActive(false); actionText.SetActive(false); ExtraCross.SetActive(false); } }
今回は以上です。