compareTag function not working in build version
I am creating a simple block fall game (v2018.1.4f1) when I test my game in the Unity Test Engine the code below works just fine. When I build the game for windows the compareTag method fails.
If I comment out "if (triggerCollider.gameObject.CompareTag("Cube"))" the code runs just fine on my Windows build. I have tried in both x86 and x86_64
I am fairly new to Unity and I am not sure if it's a problem with my scene or something else.
My Falling Block prefab is tagged as a Cube and it has the Box Collider 2D component with Is Trigger selected.
My Player component has the Box Collider 2D component and the Rigidbody 2 component. Under Rigid body component Simulated is Checked and Gravity Scale is set to 0 to keep it from falling.
void OnTriggerEnter2D(Collider2D triggerCollider)
{
if (triggerCollider.gameObject.CompareTag("Cube"))
{
if (OnPlayerDeath != null)
{
OnPlayerDeath();
}
Destroy(gameObject);
}
}
try with
if (triggerCollider.gameObject.tag ==("Cube"))
and say what you get.
And be sure the objects tag is Cube , not cube :D