i使OnTriggerEnter2D无效但不起作用

问题描述 投票:0回答:1

嗨,我使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;
        }
    }
}

shop properties

player properties

c# unity3d triggers collision void
1个回答
0
投票
您正在使用OnCollisionEnter2D回调。将其更改为OnTriggerEnter2D,看看是否可以解决您的问题。

public void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Shop") { test = true; } }

© www.soinside.com 2019 - 2024. All rights reserved.