【サバイバルホラーゲームを作りたい。その34】
今回は部屋に入るとオブジェクトが目の前を横切る仕掛けを作ります。
・オブジェクトとスフィアを配置します。
・ドアの前にオブジェクトが飛ぶトリガーとなるキューブを配置し、スクリプトを追加します。
using System.Collections; using System.Collections.Generic; using UnityEngine; public class MinorJump : MonoBehaviour //EP34追加 MinorJumpTrigにアタッチ { public GameObject flyingObj; public GameObject sphereTrig; BoxCollider boxCollider; // Start is called before the first frame update void Start() { boxCollider = this.gameObject.GetComponent<BoxCollider>(); } private void OnTriggerEnter(Collider other) { boxCollider.enabled=false; sphereTrig.SetActive(true); StartCoroutine(DeactiveSphere()); } IEnumerator DeactiveSphere() { yield return new WaitForSeconds(0.5f); sphereTrig.SetActive(false); yield return new WaitForSeconds(2.5f); flyingObj.SetActive(false); } }
今回は以上です。