-2
\$\begingroup\$

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;
        }
    }

The other parts of the script work well, but not the "Down" one, here are two objects compared to each other:

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ There is nothing to say with this limited information given. But, as it seems to me problem is not in the code, but in your scene setup. \$\endgroup\$ – S. Tarık Çetin Apr 23 '16 at 9:02
  • \$\begingroup\$ It's not limited information, it's all there is to it. I added two images of two gameobject properties, the "Up" one works but the "Down" one doesn't. It makes no sense to me \$\endgroup\$ – Ssiro Apr 23 '16 at 9:06
0
\$\begingroup\$

Apparently there were a few more objects with those tags which were colliding with the object and that's why this "bug" appeared. Deleted those objects and fixed it.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.