Hey all, I am having issues with collider and comparing tags. The collision works fine, rigid body, is set as a trigger. Once i add the IF, it doesnt seem to work. I cant find the answer online, usually to bad tags but all mine appear ok.
car is the player (rigid body and collider appear to work)
package is the pick up (Collder set as trigger, no rigid body_
private void OnTriggerEnter2D(Collider2D collision)
{
//Debug.Log("Zoom");
//This gives the proper output
Debug.Log(collision.gameObject.tag);
//Returns "Untagged"
//The game object has the proper tag in editor
if (collision.gameObject.CompareTag("Package"))
{
Debug.Log("zoom");
//Nothing happens
}
}
You don’t provide important information here, namely where is this code snippet located? Is it in the “Delivery” script? If so, the collider provided in that callback clearly isn’t going to be the one on the “Package” GameObject with the “Package” tag, it’s going to be whatever is triggering it i.e. your “car”.
If this script was on the “car” then it’d get the callback informing you that it hit the “package”, assuming you’ve got everything else set-up correctly.
As above, don’t focus on tags, output the GameObject names instead to give you more information.