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 Griffo · Feb 16, 2013 at 09:53 PM · arraygetcomponent

How would I write this?

Thank for the input, I know it looks a bit confusing .. but I'm not trying to access a string value and assign a boolean value to it, I know thats what it's trying to do as it's written ..

I want to change the "droidSphereBeingHitByGrenade" part of the line

 globalVars.GetComponent(GlobalVars).droidSphereBeingHitByGrenade = true;

into another string out of the array -

 var driodBeingHit : String[] = ["terroristBeingHitByGrenade","sentryGunBeingHitByGrenade","droidSphereBeingHitByGrenade",
                     "droidBoxBeingHitByGrenade","droidCylinderBeingHitByGrenade"];

But it looks like it's not possible to do ...

Comment
Add comment · Show 2
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 robertbu · Feb 18, 2013 at 06:00 PM 0
Share

You cannot do what you are trying to do here, but if I understand what you are trying to do, there are other ways to solve the problem. Take a look at @asafsitner answer in this post:

http://answers.unity3d.com/questions/381529/how-to-address-scripts-without-knowing-their-names.html

avatar image Griffo · Feb 19, 2013 at 10:24 AM 0
Share

robertbu, Thanks for your input and the link, interesting reading ..

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MountDoomTeam · Feb 16, 2013 at 10:04 PM

var driodBeingHit : String[] is a string. You are trying to use it as a bool.

 if(globalVars.GetComponent(GlobalVars).driodBeingHit[i] == "terroristBeingHitByGrenade"){do something}

............this is what I wrote before................. that would not check through the array, it would change the value of the array at that index.

In your explanation it seems that you are unclear in between the Boolean and the string

If you have an array of strings, and parallel array to say whether each string is true or false, that is one way of programming.

If you have an array of strings and do something with the strings, also that is fine.

You can read and write a boolean? I figure you want to read a boolean? I think you can call a function but you can only fetch and read and write a variable.

Comment
Add comment · Show 2 · 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 Griffo · Feb 16, 2013 at 10:43 PM 0
Share

Thanks for the input, but I think you'r a bit confused, (or me) maybe I'm unclear, what I want to change is just the string value in the GetComponent, the droidSphereBeingHitByGrenade part in the original line of -

 globalVars.GetComponent(GlobalVars).droidSphereBeingHitByGrenade = true;

I don't want it to check through the array I want to change that String value at that index in that part of the GetComponent ..

avatar image Griffo · Feb 17, 2013 at 07:36 PM 0
Share

I'm still stuck on this one .. Is it impossible to do ?

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

11 People are following this question.

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

Related Questions

Find GameObjects with a true boolean and put them in an array? 1 Answer

How to access multiple components of a component at once? 2 Answers

Using getcomponent with an array 2 Answers

passing multi-dimensional arrays from one script to another? 1 Answer

Get variable in script got by get component c# 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