|
I very little scripting and/or programming experiuence, but i am a quick study. This is my first real work with array, so i dont fully understand the concepts yet, but im getting there. using Unity Script What i am trying to do is dynamically create an array from objects stored in a built in array. I want the the new array to add objects that meet certain conditions. From this array, one of the objects will be 'randomly' selected for instantiation. example: -Built in array ARR contains objects A, B and C. -each object has property X. -Build array New by adding ojects from ARR with an X value above 10. -get resulting size of array New, and use that as the max value in a random range Is this possible? Is it the right way to acheive my end result? thanks
(comments are locked)
|
|
Did you read the manual? http://docs.unity3d.com/Documentation/ScriptReference/Array.html Let us know if that doesn't answer your question. in short, it does not answer my question in a way i understand. :) yep. i read all of that, But i dont understand it yet. not even sure if it says this is or is not possible... When i said very little experience, i meant little to no experiences. I am an artist trying to learn some basic scripting to prototype some ideas. This may just simply be beyond my current level of mismatched understanding. jumped ahead too far...maybe time to step back to basics. :)
Aug 01 '12 at 12:57 AM
Tsailen
Yeah, those examples on that page are pretty close to what you need. More clues here: http://docs.unity3d.com/Documentation/ScriptReference/Array.Array.html Untested:
// Creates an empty array
var newArr = new Array ();
//Now loop through original array, adding only what you need
for (var o in ARR)
{
if (o.X > 10)
// Add element to new array
newarr.Push (o);
}
// Copy the js array into a builtin array
var NEW : GameObject[] = newarr.ToBuiltin(GameObject);
Aug 01 '12 at 01:24 AM
DaveA
Awesome. While you above example was not the whole answer, it provided enough to steer me in the right direction. After scouring the ref manual, and numerous other Answer pages, i think i finally came up with a working example. I have a little more testing to do to make sure. Once i get it all working, i'll post the result for your viewing pleasure (or displeasure due to my amature code!).
Aug 01 '12 at 09:07 PM
Tsailen
(comments are locked)
|
|
After a bit of trial and error, i came up with something that worked. This is the pertinent part of the script afer cleanup. I have tested it and it does what i want. Forgive the amature code. If anyone sees a better way to do any of this, or see something i missed, let me know. objTbl.Push(obj); } } } }
(comments are locked)
|
