- Home /
problem adding an item to a builtin array
I have a problem when I try to do something like this
var enemies = new myClassName[0];
in the inspector works great, but if i want to add a new object to the builtin array directly from my .js code how i can do that? i tried this:
var enemies = new myClassName[0];
enemies.Push(new myClassName()); -> error enemies.Add(new myClassName()); -> error enemies= new myClassName(); -> error enemies[i] = new myClassName() -> i is the last index + 1 (error) enemies.Resize=N; -> error : 'self.punto.Resize' has not been correctly processed.
(and sorry for my english i speak spanish)
Answer by StephanK · Aug 03, 2010 at 09:32 AM
//this shows up in inspector var builtinArray : MyClass[];
function Start () { // this creates a js array with the contents of builtinArray var enemies = new Array(builtinArray); enemies.push(new MyClass()); }
thanks, but this way will not appear in the inspector. if I declare as Array () and not as $$anonymous$$yClassName [], I can not configure the features of my objects from the inspector, I need a form that allows me to create objects from the inspector and from. JS
Personally I don't use JS, but here http://unity3d.com/support/documentation/ScriptReference/Array.html it says that JavaScript arrays don't show up in the inspector. Builtin arrays however show up in the inspector, but can't be resized, so push and add won't work. But you CAN convert a builtin array into a JS array to get the best of both worlds.
I stole it from the documentation. You should read it sometime... ;)
Your answer
Follow this Question
Related Questions
Terrain collider - add 2 Answers
Create a game objective. 0 Answers
Add GameObjects to an Array List on RayCastHit 1 Answer
Filling up an array with GameObjects 0 Answers
I Dont Get How I Use List.Find 1 Answer