- Home /
Unity 2017 Not finding prefab tag
I have these prefab trackers drop from the player as he walks around. The enemy character is meant to stumble onto these trackers and eventually that will turn into him following the player's footsteps in order. However for some reason the enemy's trigger will not find the tagged prefabs. They are tagged on the prefab in the assets folder. If I drag and drop the prefab onto the scene it will not find the tag for the prefab game object but say for example I change the players tag it will find that. I'm not sure what's going on here. Instantiate script
void poopPrefab() {
Transform footstepPrefab = Instantiate (footPrefab, currentPos, currentRot);
}
Tag finder script
void OnTriggerStay(Collider col)
{
if (col.tag == ("tracking")) {
Debug.Log ("a thing has happened");
}
Answer by melsy · Feb 09, 2018 at 12:53 AM
const string tag = "tracking";
If (col.CompareTag(tag))
//Do something
No dice. Tried implementing as.
void OnTriggerStay(Collider col)
{
const string ftag = "tracking";
if (col.CompareTag(ftag)) {
Debug.Log ("a thing has happened");
}
}
What components are on it. A trigger needs to find an object collision with a rigidbody.
Haha! I literally just figured this out myself and was about about to close this when I saw you responded. Yes all it needed was a rigidbody thank you.
That's the way it usually works lol. But for future reference the string doesn't need to be in separate perens. Also move the const string declaration to the top of the class. It's more efficient to create strings as const so they don't get recreated every time they get called