嗨,我使OnTriggerEnter2D无效,但没有用
我在播放器中添加了刚体2d将如何触发商店
并且有箱子对撞机,并且在选手和商店被触发
但不起作用
using System.Collections.Generic;
using UnityEngine;
public class OpenShop : MonoBehaviour
{
public GameObject ShopGui;
public bool test = false;
void Update()
{
if (test == true)
{
Destroy(gameObject);
}
}
public void OnCollisionEnter2D(Collision2D collision)
{
if (collision.transform.tag == "Shop")
{
test = true;
}
}
}
OnCollisionEnter2D
回调。将其更改为OnTriggerEnter2D
,看看是否可以解决您的问题。public void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Shop")
{
test = true;
}
}