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
0
Question by Timmyglen2 · Feb 21, 2011 at 09:07 PM · javascripttagenable

How to affect multiple items with the same tag.

I am working on a script to turn on and off multiple guitexts. It is here:

var house : GameObject;
function Start () 
{
house = GameObject.FindWithTag("house");
}
function Update () 
{   
if( Input.GetKeyDown("q"))
{
house.guiText.enabled = false;
}
}

This works to turn off one of the items with the tag house, but only one. How do I change it to work for all of them?

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

Answer by Molix · Feb 21, 2011 at 09:13 PM

You can use GameObject.FindGameObjectsWithTag to get a list of all of the objects with that tag; then just iterate through the list and do it to each one.

Edit: here's an example.

var houses : GameObject[];
houses = GameObject.FindGameObjectsWithTag("house"); 
// Iterate through them and turn each one off
for (var house : GameObject in houses)
{ 
  house.guiText.enabled = false;
} 
Comment
Add comment · Show 5 · 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 Timmyglen2 · Feb 21, 2011 at 09:46 PM 0
Share

I could do it like that, but I was trying to avoid having to go through and write a line of script that does it to each one (as I have about 20 for each different tag), is there any other way?

avatar image Eric5h5 · Feb 21, 2011 at 10:09 PM 0
Share

@Timmyglen2: going through each one is the only possible way; that's how computers work. As $$anonymous$$olix said, just iterate through the array, it's trivial.

avatar image Timmyglen2 · Feb 21, 2011 at 10:27 PM 0
Share

How would I go about this? I looked at the page, but I didn't understand any of it.

avatar image reptilebeats · Feb 22, 2012 at 02:08 AM 0
Share

is there a quicker way $$anonymous$$e seems to take a second to do it to all of them at the momment im disabling all parts of a character from kinematic to enter a rigidbody state from animation. and it just seems to jump and then do it like its taking it a second to process it all.

in an old script i had i had all the different pieces written down in a long script and then i simplified it with a loop but it seems slower, is this because its got to find all the different parts before doing it. my script is only enabled when a user presses a button. should i enable the script and make an array of the objects and then put them into a if statement.

avatar image reptilebeats · Feb 22, 2012 at 02:38 AM 0
Share

scratch that last one, ill leave it there anyway as it may help people.. basically its late and im real slow and didnt realise that my animation was the problem not the loop, because my animation is constantly looping when my character goes into ragdoll its still trying to play the animation and takes a second to ignore it. simple destroy worked fine

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

1 Person is following this question.

avatar image

Related Questions

Trigger not detecting tag 1 Answer

Item pickup and activating an item afterwards help 2 Answers

Saving multiple objects with same tag 1 Answer

unity3d: making the AI jump over obstacle with a tag 1 Answer

Destroy gameobject by tag (.js) 3 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