- Home /
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 ...
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
robertbu, Thanks for your input and the link, interesting reading ..
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.
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 ..
Your answer
