(スクリプト)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GondolaSwitch : MonoBehaviour
{
public MoveFloor mf;
public GameObject door;
public GameObject door2;
public GameObject gondola;
private float posY;
private void Update()
{
posY = gondola.transform.position.y;
// ゴンドラの高さが5を超えたら移動を停止
if (posY > 5)
{
mf.enabled = false;
// 反対側のドアを開く
door2.SetActive(false);
}
}
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("Player"))
{
mf.enabled = true;
// ドアオブジェクトをワープさせて閉じる
door.transform.position = new Vector3(-1.5f, 0.5f, 0);
// ドアオブジェクトをゴンドラの子供に設定する
door.transform.parent = gondola.transform;
}
}
}
(実行)
- 最初の状態

- 乗り込むと、ドアが閉まる
- 上部方向に移動を開始する

- 移動中

- 指定の高さに到達すると移動停止
- 反対側のドアが開く
