Quantcast
Channel: Questions in topic: "join"
Viewing all articles
Browse latest Browse all 92

Best way to concat builtin arrays?

$
0
0

Incase there's an altogether better way to do this, here's the situation. I have two groups of objects in my scene, tagged ships and driftwood. The player should be able to target objects in both groups via a keypress so I need to Concat 2 builtin arrays of GameObjects into a single array which I can use GetComponent on later. At the moment I'm using this code to change the arrays from builtin to JS ones, Concat them, and then change them back (can I use GetComponent on a JS array? If so, ignore the last line).

Is this the best way to do this, or is there some easier way to have FindGameObjectsWithTag grab objects with more than one tag?

    var allaships = GameObject.FindGameObjectsWithTag ("ship");
    var allshipsjs = new Array (allaships);
    var alldriftwood = GameObject.FindGameObjectsWithTag ("driftwood");
    var alldriftwoodjs = new Array (alldriftwood);
    var concated = allshipsjs.Concat(alldriftwoodjs);
    var allships : GameObject[] = concated.ToBuiltin(GameObject);

Viewing all articles
Browse latest Browse all 92

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>