Unity OnTriggerEnter在我开始游戏时自动激活


有人能告诉我我做错了什么吗?我的void OnTriggerEnter(Collider other)方法中有一些代码,只有当我穿过盒子的对撞机时才会被调用,但当我开始游戏时,代码会立即被调用。

当我开始游戏时,Unity的OnTriggerEnter似乎会自动激活。我该如何防止这种情况发生?我确保玩家有一个对撞机。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class JumpTrigger : MonoBehaviour
{
public AudioSource Scream;
public GameObject ThePlayer;
public GameObject JumpCam;
public GameObject FlashImg;

void OnTriggerEnter(Collider other)
{
Scream.Play();
JumpCam.SetActive(true);
ThePlayer.SetActive(false);
FlashImg.SetActive(true);
StartCoroutine (EndJump ());
}
IEnumerator EndJump()
{
yield return new WaitForSeconds(1.5f);
ThePlayer.SetActive(true);
JumpCam.SetActive(false);
FlashImg.SetActive(false);
Destroy(gameObject);
}

}

当你开始游戏时,你已经在盒子对撞机中了。从而激活CCD_ 3功能。

为了保证它只在玩家越过Box Collider边界时触发,请使用OnTriggerExit((

最新更新