Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 Doneyes · May 21, 2013 at 05:48 PM · colliderplayertagweaponpickup

How can I detect if box is touching a tag named weapon?

Sorry for the basic question, but if we have a script inside of an object with a collider, how can it react to the object with a tag named weapon? I'm not asking for help doing something with the object that has the tag, but how do I get it to detect the weapon so I can then do something with it?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by clunk47 · May 21, 2013 at 05:52 PM

 void OnCollisionEnter(Collision other)
 {
     if(other.tag == "weapon")
     {
         DoSomething();
     }
 }

Check the Script Reference for OnCollisionEnter for UnityScript and C# examples.

Comment
Add comment · Show 6 · 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 Doneyes · May 21, 2013 at 08:57 PM 0
Share

I'm getting an error that says a semi colon is expected after that first line you typed. Here is the portion of the script.

 function Update () {
     void OnCollisionEnter(Collision other){
         if(other.tag == "Weapon"){
             other.transform.parent = ThrowDestination.transform; //change to pickup destination
         }
     }
 }
avatar image Tjovo-studios Doneyes · Mar 29, 2021 at 12:53 PM 0
Share

I only get this error: Assets\Skripte\Spieler.cs(22,19): error CS1061: 'Collision' does not contain a definition for 'tag' and no accessible extension method 'tag' accepting a first argument of type 'Collision' could be found (are you missing a using directive or an assembly reference?)

avatar image Bunnybomb7670 · May 21, 2013 at 09:29 PM 1
Share

you cant call it in the update, its a function what calls when collision enters, you put it outside other functions and when it collides, it calls that function onCollisionEnter, then you do a check inside the function for the tag and so on.

avatar image clunk47 · May 21, 2013 at 09:51 PM 1
Share

As I said, this is NOT a full script. This is not tested. This is just to give u an idea of what to do.

avatar image clunk47 · May 21, 2013 at 09:52 PM 1
Share

And Bunnybomb is right, don't call a void within another void, that's like calling a function inside another function. You want void Update(), void Start(), void Awake(), void OnCollisionEnter(), etc... all separated.

avatar image clunk47 · May 21, 2013 at 09:52 PM 1
Share

$$anonymous$$y example was in C# btw.

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.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Player Animation change when pickup Weapon 0 Answers

Enemy can't find weapon collider 0 Answers

specifying collider OnTriggerEnter 1 Answer

Collision detection problem 1 Answer

Inventory adds an item only once. 0 Answers


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