Hey all,
I am making a game that includes disabling and enabling the renderer of multiple objects. In my case, when the player starts, the game loads a certain amount of boxes on the screen. All of the boxes are in an array list, using System.Collections.Generic;
My problem is, when I use a for loop to enable the renderer on all of the objects, it does it one-by-one. Is there a way to make it so all of the objects are enabled at the same time? I tried messing with the .All() and .TrueForAll() methods found here MSDN but failed miserably with tons of errors. I figured it would be kind of tricky since I am using UnityScript.
Thanks!
Examples of using List.< T >.ForEach in UnityScript
#pragma strict
// Since we are using List.< T >, we need to import this:
import System.Collections.Generic;
// A list of game objects we want to do something with.
var gos : List.< GameObject >;
function Start () {
// Example 1: (If you KNOW that all game objects have a renderer)
gos.ForEach(function(g) { g.renderer.enabled = true; } );
// Example 2: (If you DONT KNOW if all game objects have a renderer)
gos.ForEach(function(g) { if (g.renderer) g.renderer.enabled = true; } );
// Example 3: (Same as Example 2, but cleaner)
gos.ForEach(EnableRenderer);
// Example 4: (Same as Example 2 and 3, but without delegates.)
for (var g in gos)
if (g.renderer)
g.renderer.enabled = true;
}
// Belongs to Example 3:
function EnableRenderer(g : GameObject) {
if (g.renderer)
g.renderer.enabled = true;
}