【サバイバルホラーゲームを作りたい。その36】
今回はパズルUIを作成します。
youtu.be
・パズルUIを作成します。
・パズルUIを表示するスクリプトを追加します。
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class RightRionPickup : MonoBehaviour //EP35追加 Right_Rion_Objにアタッチ { public GameObject actionKey; public GameObject actionText; Text actiontext; public InputScript inputScript; // public BoxCollider boxCollider; public GameObject ExtraCross; public GlobalInventory globalInventory; public GameObject HalfFade; //EP36追加 public GameObject RightRionImage; //EP36追加 public GameObject RionText; //EP36追加 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"; ExtraCross.SetActive(true); } } private void OnTriggerStay(Collider other) { if (inputScript.getInputActions()) { actionKey.SetActive(false); actionText.SetActive(false); ExtraCross.SetActive(false); globalInventory.setRightRionObj(true); //EP36追加 StartCoroutine(RionPickUp()); //EP36追加 } } //コライダーからプレイヤーが離れた場合 private void OnTriggerExit(Collider other) { actionKey.SetActive(false); actionText.SetActive(false); ExtraCross.SetActive(false); } IEnumerator RionPickUp() //EP36追加 { HalfFade.SetActive(true); RightRionImage.SetActive(true); RionText.SetActive(true); yield return new WaitForSeconds(2.5f); HalfFade.SetActive(false); RightRionImage.SetActive(false); RionText.SetActive(false); transform.parent.gameObject.SetActive(false); } }
public class GlobalInventory : MonoBehaviour //EP32追加 { bool Doorkey001 = false; bool RightRionObj = false; //EP36追加 public bool getDoorKey001() { return Doorkey001; } public void setDoorKey001(bool b) { this.Doorkey001 = b; } //EP36追加 public bool getRightRionObj() { return this.RightRionObj; } //EP36追加 public void setRightRionObj(bool b) { this.RightRionObj = b; } }
今回は以上です。