Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Ian-McCleary · Jun 12, 2015 at 02:32 AM · javascriptnetworkingdestroytag

Player tag not being detected by Unity?

I have a shooting script that i am using in my game. (Script below) It works by asking if the player is shooting, then asking if the player hit something, and then asking if the player has the tag "Player" or the tag "Vehicle" before destroying the object with that tag.

I have a debug.log setup that shows what the object i am shooting's tag is. Every time it says that the object (player) is untagged even though i created a tag and named it "Player" in unity and tagged the player prefab with it.

Im not super knowledgeable with tags, so all i did was create a new one and name it "Player" Is there something else i need to do? I even tagged the physical model of the character Player. Here is the shooting script and a screenshot of the prefab. *Note, i do not recieve the debug "TagRecieved" or "Destroyed"

 function Shoot(){
     while(true){
         if(shooting == true && weaponnum == 0 && rbullets1 > 0){
             rbullets1--;
             Physics.Raycast(transform.position,transform.forward,hit);
             Debug.Log(hit.collider.tag);
                 if(hit.transform !=null){
                 Debug.Log("HitPlayer");
                     if(hit.collider.tag == "Player" || hit.collider.tag == "Vehicle"){
                         Debug.Log("tagrecieved");
                         Network.Destroy(hit.transform.gameObject);
                         Debug.Log("Destroyed");
             }
         }
         AudioSource.PlayClipAtPoint(aeksound, transform.position);
     }
                 else if(weaponnum == 0 && rbullets1 == 0){
                     yield WaitForSeconds(2);
                     if(rbullets >= 30){
                         rbullets -= 30;
                         rbullets1 += 30;
             }
             else if(rbullets < 30){
                 rbullets1 += rbullets;
                 rbullets = 0;
             }
         }
         if(shooting == true && weaponnum == 1 && pbullets1 > 0){
             pbullets1--;
             AudioSource.PlayClipAtPoint(walthersound, transform.position);
             Physics.Raycast(transform.position,transform.forward,hit);
             Debug.Log(hit.collider.tag);
                 if(hit.transform !=null){
                     Debug.Log("HitPlayer");
                     if(hit.collider.tag == "Player" || hit.collider.tag == "Vehicle"){
                     Debug.Log("TagRecieved");
                     Network.Destroy(hit.transform.gameObject);
                     Debug.Log("Destroyed");
             }
         }
     }
                 else if(weaponnum == 1 && pbullets1 == 0){
                     yield WaitForSeconds(2);
                     if(pbullets >= 30){
                         pbullets -= 30;
                         pbullets1 += 30;
             }
             else if(pbullets < 30){
                 pbullets1 += pbullets;
                 pbullets = 0;
         }
 }
         if(weaponnum == 0)
             yield WaitForSeconds(.075);
         else if (weaponnum ==1)
             yield WaitForSeconds(.5);
     }
 }


alt text

2015-06-11-1930.png (71.3 kB)
Comment
Add comment · Show 5
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 Mouton · Jun 12, 2015 at 06:13 AM 0
Share

Player is a built-in tag, you shouldn't recreate it. I just tried on my project and it causes multiple issues. I am not sure why but the new tag doesn't appear in the list, and if I force the game to use it, it will result in an "Untagged" gameobject.

Delete your "Player" tag and use the built-in one.

avatar image Ian-McCleary · Jun 12, 2015 at 07:52 AM 0
Share

I made a whole new tag and called it Human, even when i try different tags it wont work. Is there something else that defines a tag? Is my code wrong for detecting tags?

avatar image fafase · Jun 12, 2015 at 08:01 AM 0
Share
 if(shooting == true && weaponnum == 0 && rbullets1 > 0)
 {
     rbullets1--;
     Physics.Raycast(transform.position,transform.forward,hit);
     Debug.Log(hit.collider.tag);
     //if(hit.transform !=null)  // No need, all GO have Transform
     //{
     Debug.Log("HitPlayer");
         Debug.Log(hit.collider.tag); // What is the tag it hits?
     if(hit.collider.tag == "Player" || hit.collider.tag == "Vehicle")
     {
         Debug.Log("tagrecieved");
         Network.Destroy(hit.transform.gameObject);
         Debug.Log("Destroyed");
     }
     //}
     AudioSource.PlayClipAtPoint(aeksound, transform.position);
 }

Now it will tell you why the tag is not detected. $$anonymous$$aybe it is hitting something else. Also, As I mentioned, no need to check for Transform, all GameObject have a Transform by default so it cannot be missing since it cannot be removed.

avatar image Ian-McCleary · Jun 12, 2015 at 08:20 AM 0
Share

Thank you so much. It turn out that my "bullets" are just hitting the terrain and not the player.

Do you know if this line of code is relative to global or the player? Or even where it would relay from? (im not super knowledgeable with raycasts)

 Physics.Raycast(transform.position,transform.forward,hit);

avatar image fafase · Jun 12, 2015 at 08:41 AM 0
Share

If transform.position refers to the player then it will be ignored:

   "Raycasts will not detect colliders for which the raycast origin is inside the collider. "

2 Replies

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

Answer by Ian-McCleary · Jun 18, 2015 at 11:31 PM

If you want to know what i did, @fafase helped me out to understand what the tag it was actually getting. Turns out my whole raycast was screwed up. @fafase if you change your comment to an answer im happy to make it correct.

I ended up ditching the whole system because it was made poorly.

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 devsanunity · Apr 12, 2020 at 12:19 PM

Im facing the same problem. What was the exact solution? @fafase @Ian-McCleary

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.

Follow this Question

Answers Answers and Comments

23 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

Related Questions

Destroying GameObject in NetworkBehavor with Javascript 0 Answers

Destroy gameobject by tag (.js) 3 Answers

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

Character Controller is not interacting with colliders. 1 Answer

how do i create a game object array with gameobjects of multiple tags 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