- Home /
Tags not working?
I'm having some problems with the tags at the unity, they are not working i think. What i want is that when the character collides with the ammo, the ammo object is destroyed, and then the character ammo is recharged.
here is the code:
#pragma strict
function Start () {
}
function Update () {
}
function OnCollisionEnter(collision: Collision)
{
if (collision.gameObject.tag == "jogador")
{
Destroy(gameObject);
Arma.contMunicao = Arma.contMunicao+100;
}
}
the variables are in portuguese(br)
the character is tagged with the tag "jogador", but when it collides nothing happens.
the collision is working well so i think is a problem with the tags. waiting :)
Hi! Your character object or the ammo object have a rigidbody component?
try printing (debugging) gameobject first and check if collision detction is proper.For this kind of scenarios try using onTriggerEnter rather oncollisionEnter.
void OnCollisionEnter(Collision col)
{
print ("Hero tanker just hit gameobject name : "+col.collider.gameObject.name);
}
Hope this may help you. -Nsks
@username $$anonymous$$indly Check these in your Project.
$$anonymous$$ake sure that Rigidbody is attached to one of the colliding object.
$$anonymous$$ake sure that both objects have
colliders attached to them and
IsTrigger check of both the colliders is false too.
Answer by KokodokoGames · Feb 16, 2018 at 11:22 AM
You can log the tag after a collision:
function OnCollisionEnter(collision: Collision){
Debug.Log(collision.gameObject.tag);
}
In my case, this is causing problems too. My gameobject is tagged but the log says the object is "unTagged". I even tried adding a new different tag, but it just stays untagged... :(
Your answer
![](https://koobas.hobune.stream/wayback/20220613133023im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Showing a picture on collision errors 1 Answer
Block Collision Sliding off 0 Answers
Collision destroy help. 1 Answer
I got an error that will not go away and doesn't seem to have a solution. 2 Answers