x


can you have a Tag inside a tag and check for collision with that?

currently i have a Player (moves and stuff) (tagged Player)within the Player i have a sword which (tagged sword). i want to check if a cube hits the sword. how would i go about this?

i have tried using triggers and normal collision (have used rigidbody, box, spehere,mesh...collders)

this script is attached to a cube

function OnCollisionEnter(hit : Collision) {

if (hit.gameObject.tag=="sword"){ print ("hit"); }}

more ▼

asked May 06 '11 at 08:31 AM

Emo gravatar image

Emo
11 2 2 7

Why don't you try it first before you post a question? Yes, it's a workable solution.

May 06 '11 at 09:27 AM Dreamer

obviously i have tried all solutions before i posted here

May 06 '11 at 10:26 AM Emo

use Debug.Log(hit.gameObject.tag);

May 06 '11 at 12:45 PM Aldwoni

It's probably easier to add a script to the player keeping track of all the data. Like weapon: sword; health: x; stamina: y; etc..

May 06 '11 at 02:13 PM Joshua
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

You didn't say what exactly is happening, but odds are you are having the common problem of not getting notified of any collisions. If you search Answers for OnCollision and OnTrigger you can see how other people have fixed it. Make sure both objects have colliders; one of them needs a Rigidbody on it as well.

It's possible that OnCollisionEnter IS getting called, in which case the problem may be with your If statement. Make sure you spelled and capitalized the tag name correctly in your code. Aldwoni's suggestion can help you see if that's happening: add his Debug.Log command to the first line of your OnCollisionEnter method, or use breakpoints (if you are debugging with MonoDevelop.)

more ▼

answered May 06 '11 at 01:42 PM

Bampf gravatar image

Bampf
5.1k 8 20 49

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

if you want a tag inside a tag you can use the inside string to determine your inner tag example

your object tag could be "ArmSword"

hit.gameObject.tag.contains("Sword")

the contains will see that your tag have Sword in it so it will be detected as sword, but if you use

hit.gameObject.tag.contains("Arm")

then it will be considered as Arm

is just a vague example but is the easiest way to use your tag inside a tag

more ▼

answered May 06 '11 at 02:09 PM

poncho gravatar image

poncho
932 2 3 14

(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:

x3571
x2584
x337
x33

asked: May 06 '11 at 08:31 AM

Seen: 1494 times

Last Updated: May 06 '11 at 12:20 PM