4 回答

TA貢獻1752條經驗 獲得超4個贊
您可以使用
gameObject.SetActive(true); gameObject.SetActive(false);
您只需在 TriggerEnter 和 TriggerExit 中調用它。我不知道你是否想讓你的“ghostapparition”不活動,但它是:
GhostApparition.SetActive(true); GhostApparition.SetActive(false);

TA貢獻2012條經驗 獲得超12個贊
….monobehavior:
public GameObject object;
void Start()
{
object.SetActive(false);
object2.SetActive(false);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
{
object.SetActive(true);
object2.SetActive(false);
}
}
}
/// void OnTriggerStay and 'object2' are extras (for if u want a keycode to show an additional text)
void OnTriggerStay(Collider other)
{
if (object.activeInHierarchy && Input.GetKeyUp(KeyCode.E))
{
object.SetActive(false);
object2.SetActive(true);
}
}
void OnTriggerExit(Collider other)
{
object.SetActive(false);
object2.SetActive(false);
}
...

TA貢獻1936條經驗 獲得超7個贊
要解決這個問題,只需這樣做:
GameObject GhostApparition;
// Use this for initialization
void OnTriggerEnter (Collider other)
{
if (other.tag == "Player") ;
{
GhostApparition.SetActive(true);
}
}
void OnTriggerExit (Collider other)
{
if (other.tag == "Player") ;
{
GhostApparition.SetActive(false);
}
}
但是當你使用包含行為的游戲對象時要注意。如果您停用它,然后再次激活,它將再次運行 void Start 并重置您的變量。有時你不會想要它。
所以我建議,在這些時候,您只需停用GameObject MeshRenderer組件即可。
- 4 回答
- 0 關注
- 119 瀏覽
添加回答
舉報