【サバイバルホラーゲームを作りたい。その39】
今回はパズル要素の続きを実装していきます。
youtu.be
・ステージを追加し、前回の残りのオブジェクトを配置します。
・オブジェクトを取得できるようにスクリプトを追加します。
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class LeftRionPickup : MonoBehaviour //EP39追加 Left_Rion_Objにアタッチ { public GameObject actionKey; public GameObject actionText; Text actiontext; public InputScript inputScript; public GameObject ExtraCross; public GlobalInventory globalInventory; public GameObject HalfFade; public GameObject LeftRionImage; public GameObject RionText; Text RText; private void Start() { actiontext = actionText.GetComponent<Text>(); RText = RionText.GetComponent<Text>(); } private void OnTriggerEnter(Collider other) { //コライダーにプレイヤーが当たった場合 if (other.tag == "Player") { // Debug.Log("hit"); //キー押下~のメッセージを表示 actionKey.SetActive(true); actionText.SetActive(true); actiontext.text = "Pick Up"; ExtraCross.SetActive(true); } } private void OnTriggerStay(Collider other) { if (inputScript.getInputActions()) { actionKey.SetActive(false); actionText.SetActive(false); ExtraCross.SetActive(false); globalInventory.setLeftRionObj(true); globalInventory.StalkerAIOFF(); StartCoroutine(RionPickUp()); } } //コライダーからプレイヤーが離れた場合 private void OnTriggerExit(Collider other) { actionKey.SetActive(false); actionText.SetActive(false); ExtraCross.SetActive(false); } IEnumerator RionPickUp() { HalfFade.SetActive(true); LeftRionImage.SetActive(true); RionText.SetActive(true); RText.text = "YOU GOT THE LEFT PIECE"; yield return new WaitForSeconds(2.5f); HalfFade.SetActive(false); LeftRionImage.SetActive(false); RionText.SetActive(false); transform.parent.gameObject.SetActive(false); } }
・左右オブジェクトを取得した場合、ミュータントの動きをOFFにします。
public class GlobalInventory : MonoBehaviour //EP32追加 { (省略) //EP39 左右ライオンオブジェクトを取得した場合、ミュータントをOFF public void StalkerAIOFF() { if(RightRionObj && LeftRionObj) { stalkerAI.setIsStalking(false); } } }
public class RightRionPickup : MonoBehaviour //EP35追加 Right_Rion_Objにアタッチ { (省略) private void OnTriggerStay(Collider other) { if (inputScript.getInputActions()) { actionKey.SetActive(false); actionText.SetActive(false); ExtraCross.SetActive(false); globalInventory.setRightRionObj(true); //EP36追加 globalInventory.StalkerAIOFF(); //EP39追加 StartCoroutine(RionPickUp()); //EP36追加 } } }
今回は以上です。