I tried searching a bit for this but the phrasing makes it a difficult search. I’m looking for the unity way to simply do this:
var physics_objects = ["some_prefab_2", "some_prefab_7", "some_prefab_8"];
…
if ("some_prefab_2" in physics_objects) {
do_something_with_physics("some_prefab_2");
}
What is the approprate way to do this in Unity. The “in” operator doesn’t seem to work from Javascript. Thanks!
EDIT: I would like to avoid looping through an array of strings if possible unless there is no built in method that would be more efficient.
Use a for loop, check each value in the array to see if it is equal to your string. for (int i = 0, i < physics_objects.length, i++){ if (physics_objects == "some_prefab_2"){ do something; } }
– OlgoSorry - I meant to add that to my original question. I'm trying to avoid looping for obvious reasons unless there is no built in method that would be faster. Thanks
– ensomniacah I see, I will convert my answer to a comment so this question gets more attention.
– Olgo