• 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 · gameobjecttagsdisableenabled

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

  • 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Information about Behaviour.enabled 1 Answer

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

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

Disalbe/Activate script if a key is pressed. 1 Answer

Gameobject script enable weird behavior 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