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 /
This question was closed Sep 04, 2013 at 06:22 PM by clunk47 for the following reason:

Too subjective and argumentative

avatar image
0
Question by asdf123 · Sep 04, 2013 at 03:27 PM · c#gameobjecttagweaponpick

Pick all gameobject with specific tag

Using GameObject.FindGameObjectsWithTag, how can I set ALL of the gameObjects with a specific tag inactive?

e.g:

 if(Input.GetKeyDown(KeyCode.Q)) 
 {
     (all gameobjects with tag "PrimaryWeapon").SetActive(false);
 }

in C#

someone can help?

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

  • Sort: 
avatar image
3
Best Answer

Answer by clunk47 · Sep 04, 2013 at 05:04 PM

Here's a C# example of how to use an Array and GameObject.FindGameObjectsWithTag.

 using UnityEngine;
 using System.Collections;
 
 public class Example : MonoBehaviour 
 {
     GameObject[] primaryWeapons;
     
     void Start()
     {
         primaryWeapons = GameObject.FindGameObjectsWithTag("PrimaryWeapon");
     }
     
     void Update()
     {
         if(Input.GetKeyDown(KeyCode.Q))
         {
             if(primaryWeapons.Length > 0)
             {
                 foreach(GameObject pw in primaryWeapons)
                 {
                     pw.SetActive(false);
                 }
             }
         }
     }
 }
 
 

Notice the plural in FindGameObjectsWithTag 'Objects', be sure not to mix this up with 'Object'.

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 perchik · Sep 04, 2013 at 05:05 PM 2
Share

Clunk to the rescue, with the actual answer ;)

avatar image Ozcorps · Sep 04, 2013 at 05:13 PM 2
Share

Thanks Clunk47 nice to see people giving information for the lazy or maybe bad google searchers. Not everyone can be as good as the professionals above who only know how to put people down..

i agree with them but for people like myself looking for the same answer im getting tired of searching and finding the same sort of results as this post has, but with no actual answer.. So great to see you working for us(the lamer programmer).

Cant wait for those 2 to get stuck and they run down the same road as asdf123 and get crap thrown there way.. Not attacking just getting tired of same information EVERYWHER$$anonymous$$ There be NO GOOGLE if we didnt place a answer First.

avatar image perchik · Sep 04, 2013 at 05:17 PM 3
Share

For the record, the google hit was not a unity answer, it was the Unity Documentation page. When you type this question into google, word for word, the first hit is GameObject.FindGameObjectsWithTag It's not like you have to have some kind of super google kung fu, it's literally the first hit.

Also, it's disrespectful to the community to ask a question (and waste their time) that is literally as easy as pasting it into google.

There were actually two questions here--how do I get all the game objects with a tag and then how do I do something with it all. If the OP had posted that he had found FindGameObjectsWithTag and had tried code to use it, but it didn't work, then I would have been glad to answer the question.

avatar image clunk47 · Sep 04, 2013 at 05:26 PM 1
Share

I agree to some extent here with @perchik, this is why I edited your question. The google link he posted is legitimate, it links you to the Unity Script Reference page for the first part of your question needed. I won't say you're lazy for it though, I'll just say take the advice that is actually helpful and use it as a future reference, ignore the rest of the unnecessary remarks. Feel free to come back and ask more questions, just try to be as helpful as possible explaining your concerns.

avatar image perchik · Sep 04, 2013 at 06:05 PM 1
Share

No. Your question was edited to make you look better, the previous comments were because of your original question.

Show more comments

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Distribute terrain in zones 3 Answers

How do I find the closest target with a tag? c# 2 Answers

Find all objects that has specific tag 2 Answers

Multiple Cars not working 1 Answer

how to use itween with the object attached to other moving object 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