- Home /
Question by
Ssiroo · Apr 23, 2016 at 09:02 AM ·
c#3dontriggerenterontriggerexitbooleans
Unity3D: Entering a trigger disables a few bools for no reason
I'm trying to make it so when an object enters a collider with the tag "Down" a single boolean turns false, but the problem is that more than one booleans(canGoUp, canGoLeft, canGoRight) are turning false for no reason, here's my code.
void OnTriggerEnter(Collider col)
{
if(col.gameObject.tag == "Up")
{
canGoUp = false;
}
if (col.gameObject.tag == "Down")
{
canGoDown = false;
}
if (col.gameObject.tag == "Left")
{
canGoLeft = false;
}
if (col.gameObject.tag == "Right")
{
canGoRight = false;
}
}
void OnTriggerExit(Collider col)
{
if (col.gameObject.tag == "Up")
{
canGoUp = true;
}
if (col.gameObject.tag == "Down")
{
canGoDown = true;
}
if (col.gameObject.tag == "Left")
{
canGoLeft = true;
}
if (col.gameObject.tag == "Right")
{
canGoRight = true;
}
}
Here are two objects compared to each other, the "Up" one works but the "Down" one doesn't.
89242817de4d65b3cf99329b2b018864.png
(38.5 kB)
d334e29668a3e21778575d95a85e1cb2.png
(39.3 kB)
Comment
Best Answer
Answer by Ssiroo · Apr 23, 2016 at 09:51 AM
Apparently there were some other objects in the scene using those tags and they were colliding with the object, deleted them and that fixed it.