【发布时间】:2021-02-18 14:57:46
【问题描述】:
标题听起来令人困惑,但为了简单起见……我有两个触发器,或者“压力板”,如果你愿意的话,它们连接到一扇门。当两个物体都在扳机中时,门会升高两倍。这就是问题所在,我需要门的变换在一个或两个触发器都处于活动状态的情况下保持不变,但当两个触发器都不活动时仍会重置为原始位置。 [下面提供的触发器代码]
如果有人对此有任何想法,请告诉我。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PadTriggerPlayer1 : MonoBehaviour
{
public GameObject door;
public float Height = 0f;
public bool doorOpened = false;
void OnTriggerEnter(Collider col)
{
if(col.gameObject.tag == "Player1")
{
door.transform.position += new Vector3(0f, Height, 0f);
doorOpened = true;
}
}
void OnTriggerExit(Collider col)
{
if(col.gameObject.tag == "Player1")
{
door.transform.position += new Vector3(0f, -Height, 0f);
doorOpened = false;
}
}
}
【问题讨论】:
-
宁愿有一个专门的班级,门上有一个标志/计数器,只在第一个触发器进入时做你的事情?