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 joseph 1 · Apr 28, 2011 at 03:25 PM · objectgameinstancefindall

All instance of a script and change a variable

Hi Guys

I have a prefab and 5 or 6 of its instance on the scene. There is a move script attached to the prefab with a variable. How can I accesse to every single instance of the game object and change the variable in the same time? GameObject.Find/FindWithTag seems to find only one of them but not all with the same name. If you have any idea can you help me in Javascript please? Thanks Jozsef

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 flaviusxvii · Apr 28, 2011 at 03:27 PM 0
Share

Javascript is NOT Java!!!!! Spread the word!

avatar image joseph 1 · Apr 28, 2011 at 03:39 PM 0
Share

Thnx flaviusxvii. Any idea now ??

avatar image Uriel_96 · Apr 28, 2011 at 04:04 PM 0
Share

you can use var example = GameObject.FindGameObjectsWithTag("object"); and what it does is search for all the objects that have that tag and you access to this using example[0].blablabla

avatar image Uriel_96 · Apr 28, 2011 at 04:05 PM 0
Share

(sorry for 2 comments) http://unity3d.com/support/documentation/ScriptReference/GameObject.FindGameObjectsWithTag.html

avatar image joseph 1 · Apr 28, 2011 at 04:38 PM 0
Share

Yeah thanks I have just found the same solution you are talking about on a different forum. I will try it. thanks for the reply.

1 Reply

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

Answer by Richard J. Hansen · Apr 28, 2011 at 04:04 PM

You could take advantage of sending messages, just give all the prefabs some function to change the variable. However that can be slow if you are doing it alot.

If you are instatiating the prefabs at run time, simply store them in an array. You can then loop through the array changing all the variables.

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

No one has followed this question yet.

Related Questions

find object in game view 1 Answer

How could I get a selection set of GameObject sharing a material or a script in Editor? 1 Answer

End game then an Object is close to another object? 0 Answers

Sound when see gamect? need help 2 Answers

How to deactivate objects that are children all at once? 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