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
2
Question by code-blep · Aug 09, 2012 at 05:09 PM · javascriptmultiplenamesame

Multiple scripts with the same name issue

Hi,

I have a gameobject (VisualizerManager) with multiple scripts of the same name (VisDataGroup), and I am having problems targeting the correct script in JavaScript. It seems the Unity searches through them in order and finds the first one.

I cannot rename the scripts as they are part of the Visualiazer Studio component.

Each script does have a value in it of DataGroupName which can be used to distinguish between them, their unique values are: Bass, Mid, High.

Is this the best route to go to try and target the right script?

Currently I target the first one successfully like this:

 thevisualizermanager.GetComponent("VisDataGroup").boost = 2;

"boost" is the value I am changing in them. I need to change them all to different values so I need to be specific about which one.

Any ideas and pointers in the right direction will be much appreciated.

Thanks.

Paul

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
2
Best Answer

Answer by Dragonlance · Aug 09, 2012 at 05:36 PM

Hi UFO Hunter,

what about

 VisDataGroup[] visDataGroups = thevisualizermanager.GetComponents<VisDataGroup>();
 foreach (VisDataGroup visDataGroup in visDataGroups) {
     // Check the Id here and act accordingly
 }
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 code-blep · Aug 09, 2012 at 08:13 PM 0
Share

Hey Dragonlance,

Thanks for the suggestion. However it gives me 9 errors for all lines. For example: expected. Insert a semicolon at the end.

Unexpected token: )

expecting ), found 'visDataGroup'

expecting EOF, found '}'

I've not used foreach commands before, so I'm not sure about the correct syntax to use, but will go and research it now.

avatar image Screenhog · Aug 10, 2012 at 10:02 PM 0
Share

The theory looks sound, though. Create an array of your VisDataGroup components, and then you have a way to identify each one.

I haven't used foreach before, though. I'd use a regular for loop.

avatar image code-blep · Aug 18, 2012 at 06:30 PM 0
Share

Thanks Screenhog. I have not been able to get this working and may leave it for a while. Can someone suggest how I should deal with the answers given as I can seem to be able to confirm them.

avatar image Dragonlance · Aug 18, 2012 at 08:37 PM 2
Share

UFO maybe it is because my snippet is in C# and you are working in javascript. You will have to adapt it.

Sorry for that, but I did not see that you are only into javascript from your post.

 var visDataGroups : VisDataGroup[];
 visDataGroups = gameObject.GetComponents (VisDataGroup);
 for (var visDataGroup : VisDataGroup in visDataGroups ) {
      // Check the Id here and act accordingly
 }
avatar image code-blep · Aug 19, 2012 at 01:56 PM 0
Share

Thanks DragonLance!

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

beginner question- several errors 1 Answer

Getting a scene object's name 1 Answer

How do I use current List Object [i] as the string name? 3 Answers

Using a Variable over two Scripts 4 Answers

As I can assign a script to an object using JavaScript? 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