What I am trying to do here is to list a series of cubes into an array, and then form a GUI menu generated dynamically, to create buttons that disable one cube or another using renderer.enabled
I don’t seem to get the syntax right
Can somebody help just in pointing where in my object what I am missing or doing wrong?
Thanks
yves
var cubes : GameObject[ ]= GameObject.CreatePrimitive(PrimitiveType.Cube);
There are multiple errors in your code… Here are some suggestions to at least get you closer:
Should give a compile error; you can’t initialize an array of GameObjects to an instance of GameObject. You also probably don’t want to be creating an extra cube in your scene every time the game starts. Remove the initialization and set the cubes to the array via the inspector.
You can’t loop over a type. You probably meant ‘for( var I in cubes )’ here.
What is ‘newarr’ supposed to represent here? This should be a compile error too I think, but it’s unneeded anyway.
You declared ‘newarr’ as a local variable, but you’re trying to access it as a member of ‘I’… With your original code ‘I’ couldn’t receive a valid value, but assuming it’s meant to be a reference to one of your cube GameObjects, it’s still not going to have a ‘newarr’ member. Likewise, ‘.Cube’ isn’t going to reference anything that exists anywhere. This should be closer to what you need: