I’m counting down the collisionCount to get button out if I crash three times.
However, the collisionCount is not counted properly, so it continues to be counted as 1.
I’m asking questions because I don’t know what the problem is. Please help.
enter image description here
public class ItemPickUp : MonoBehaviour
{
GameObject player;
private StartMng mng; // StartMng 변수 mng
int collisionCount = 0;
// Start is called before the first frame update
void Start()
{
this.player = GameObject.Find("player");
mng = FindAnyObjectByType<StartMng>(); //mng로 StartMng의 오브젝트들을 전부 가져옴
}
// Update is called once per frame
void Update()
{
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject == player) // 플레이어랑 충돌하면
{
collisionCount++;
Debug.Log($"충돌 횟수: {collisionCount}");
Destroy(gameObject); // 지움
mng.ActivePanel(collisionCount); //mng에서 PanelActive를 불러옴
if (collisionCount == 3)
{
mng.StartBtnClick();
}
}
}
}
CollisionCount should be added 1 by 1 in 1, 2, 3. But this code doesn’t add up.
CollisionCount continues to be 1.
I wonder what to do with this little error.
jin ichi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.