Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 izimonster7 · Jun 19, 2018 at 03:00 AM · tagtriggerstaggingdetecting

How do you find the tag of the object that is a trigger?

So, I'm new to unity, so I don't know if this is possible, but: How do you check the tag of the object that is in a trigger? Any way to do this would work.

For example, I have a two player game with a selection screen that uses two cursors to choose, and I want the buttons to be able to discern the tag (Player1 and Player2) so that my game knows which character is chosen by which player. On a side note, the cursors are rigidbodies, and the "button" is a trigger. This is because it is local multiplayer, meant to be played on a single keyboard.

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
0
Best Answer

Answer by Feelnside · Jun 19, 2018 at 04:48 AM

You don't need to use the tags there.

Once a Player has clicked the Player1 button, you need to assign to him that you are the Player1.

For example you can use int playerID (0 - not selected, 1 - Player1, 2 - Player2) at each Player.

Once the Player clicks the Player1 button, we need to ask another Player "what is your playerID?". If ID is not equal to the selected button, we can assign it to the Player like playerID = 1;

Comment
Add comment · Show 8 · 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 izimonster7 · Jun 19, 2018 at 08:09 PM 0
Share

Oh. Sorry, I forgot to mention this was local multiplayer. Unless i'm interpreting your answer incorrectly?

avatar image Feelnside izimonster7 · Jun 20, 2018 at 05:58 PM 0
Share

Are you using rigidbodies (cursors) and trigger (button)?

In case if yes, you can add to the first cursor the "Player1" tag and to the second one the "Player2" tag.

And then just add a script into the trigger (button)

 void OnTriggerEnter(Collider col)
 {
      if(col.CompareTag("Player1"))
      {
           //this is the 1st Player
      }
      else if(col.CompareTag("Player2"))
      {
           //this is the 2nd Player
      }
 }
avatar image izimonster7 Feelnside · Jun 22, 2018 at 01:11 AM 0
Share

It seems for me that OnTriggerEnter isn't working at all. I have a print command located in OnTriggerEnter and it doesn't seem to be working. $$anonymous$$y button is a trigger and both cursors are rigidbody2d, but the console doesn't print anything when they collide.

Show more comments

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

86 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Detecting collisions 3 Answers

Game wont restart in the build, but works great in the editor.. 1 Answer

colliding with child trigger? 0 Answers

Destroying Multiple Objects with Tags 1 Answer

Set a Tag Multiple GameObject[] 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