- Home /
Trigger won't recognise tag
I am trying to test that my trigger can recognize an object in it by its tag. The tag is on my player object and the script below is attached to the same game object as my trigger. When I run the game the word "Gravity" is printed in the console whenever my player is within the trigger, but "Tag is correct" is not. What do I need to do to get it to print?
void OnTriggerStay(Collider ob) { print (ob.tag); if (ob.tag == "Gravity") { print ("Tag is correct"); } }
Answer by robertbu · Mar 02, 2014 at 05:00 AM
The code looks fine. To start with, go to the tag manager and copy the tag string, then paste that same string in here to make absolutely sure the two strings are the same...same case, no extra spaces, same spelling, etc.
I managed to fix it by going into the tag manager like you said, deleting the tag and then retyping it. It was written the same both times, so it must have been some glitch in Unity (or just me not seeing something obvious)