• 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
Question by Fusobotic · Jun 26, 2010 at 08:33 PM · gameobjectdisabletagsenabled

Enabling/Disabling Multiple Tagged objects

I'm having a little trouble trying to disable some objects through a level controller script. Basically I've tagged multiple objects with the tag "zones" (they're triggers) and I want to disable all of them through a single controller script. Whenever I tried stating a var and then containing all the gameobjects within it with the "FindGameObjectsWithTag()" it didn't work, then I tried doing it in one line of code instead:

GameObject.FindGameObjectsWithTag("zones").enabled = false;

Any suggestions? It returns an error : "enabled is not a part of UnityEngine.GameObject", with both techniques. btw, I'm using the the line of code inside of an Update function.

Comment
dissidently
ImJackWorthington
vama89

People who like this

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

Answer by Mike 3 · Jun 26, 2010 at 09:14 PM

That's because it's returning a gameobject array, not a single gameobject (and on top of that, it's active for gameobjects, not enabled)

you can do something like this:

for(var go : GameObject in GameObject.FindGameObjectsWithTag("zones"))
{
    go.active = false;
}
Comment
Fusobotic
Thom Denick
dissidently
Barrett-Fox
Lilius
vama89

People who like this

6 Show 3 · 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 Fusobotic · Jun 26, 2010 at 10:25 PM 0
Share

So this'll work if I just cut & paste? Or do I have to rename a few things, or change something in a different area of script?

avatar image Mike 3 · Jun 26, 2010 at 10:41 PM 0
Share

It should just work pretty much anywhere (within reason - it has to be compilable ;) )

avatar image Orggrim · May 24, 2013 at 08:13 AM 0
Share

I would like to note Mike3 that you just solved my Camera Array problem!!!!! TY TY TY TY TY TY TY

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

1 Person is following this question.

avatar image

Related Questions

gameObject.GetComponent("Script").enabled = true not working 5 Answers

Disabling THIS script from code 1 Answer

How to make an open and close box?,How to make open and close a box? 0 Answers

Gameobject script enable weird behavior 1 Answer

Toggling a script on/off using the keyboard? 2 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