• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Emo · May 06, 2011 at 08:31 AM · javascriptcollisiontaginside

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"); }}

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dreamer · May 06, 2011 at 09:27 AM 0
Share

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

avatar image Emo · May 06, 2011 at 10:26 AM 0
Share

obviously i have tried all solutions before i posted here

avatar image Aldwoni_legacy · May 06, 2011 at 12:45 PM 0
Share

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

avatar image Joshua · May 06, 2011 at 02:13 PM 0
Share

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bampf · May 06, 2011 at 01:42 PM

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.)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by poncho · May 06, 2011 at 02:09 PM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

On Click, destroy object and any colliding object with the same tag. 6 Answers

Collide detection with tag [JS] 0 Answers

Rigidbody Collision detection 1 Answer

Substitute of collision 2 Answers

Trigger not detecting tag 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges