x


hit.gameObject.tag throws error.

Right, I have a script that does various things depending on what the collider hits. To check that the collider hit the right object before it does anything i'm using:

if(hit.gameObject.tag == "donkey") { }

It all works 100% when it hits the object with that tag but if it hits an object with a different tag it throws off this error: UnityException: GameObject has undefined tag!

Any help would be much appreciated!

more ▼

asked Jul 22 '11 at 05:18 AM

Tides gravatar image

Tides
31 15 19 21

Is hit in fact a RaycastHit? If so, that really shouldn't work at all.

Jul 22 '11 at 02:53 PM djmorrsee

We would really need to see a bit more of the code to help out. What is "hit"? If you can post the whole function, that would help us help you a lot

Jul 22 '11 at 07:17 PM Kith
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

It seems like he's using OnControllerColliderHit(hit : ControllerColliderHit). But either way you change it to if(hit.gameObject.tag == ("donkey")) after that it should work just fine

more ▼

answered Nov 10 '11 at 05:47 AM

ocularcash gravatar image

ocularcash
108 4 7 8

(comments are locked)
10|3000 characters needed characters left

Just ran into this problem. This seems to have worked:

    else if( Other.gameObject.tag == "Untagged" )
    {
       // Debug.Log("Hit an object with an undefined tag");
    }
more ▼

answered Dec 07 '11 at 09:56 AM

rbisso gravatar image

rbisso
31 2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1949
x1692
x193
x6

asked: Jul 22 '11 at 05:18 AM

Seen: 1217 times

Last Updated: Dec 07 '11 at 09:56 AM