Home > database >  How can I trigger a boxcollider2d
How can I trigger a boxcollider2d

Time:11-25

I have no idea why my trigger system isn't working I have 2 objects, both with box colider 2D, the first object is tagged Player and Box Colider 2D isn't set to trigger, the second one is untagged, Box Collider 2D is set to trigger and contains the following code :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
   
public class hit : MonoBehaviour
{      
    public void OnTriggerEnter(Collider other)
    {          
        if (other.gameObject.tag == "Player") 
        {               
            Debug.Log("triggered");
        }
    }
}

Nothing happens when the first one passes through the second one.

Could someone help me?

CodePudding user response:

you probably need the OnTriggerEnter2D method

void OnTriggerEnter2D(Collider2D collision)
{
    Debug.Log("GameObject collided with "   collision.name);
}
  • Related