- Home /
BCE0019: 'Add' is not a member of 'UnityEngine.Transform[]'
I need help with a problem I get in my code. I am writing a code to generate a maze using Prim's Algorithm. This is the code I get the error on: function SetAdjacents() { var x : int; var y : int; for(x = 0; x < size.x; x++) { for(y = 0; y < size.y; y++) { var cell : Transform; cell = grid[x,y]; var cScript : CellScript = cell.GetComponent(CellScript); if(x - 1 >= 0) { cScript.adjacents.Add(grid[x-1,y]); } if(x + 1 < size.x) { cScript.adjacents.Add(grid[x+1,y]); } if(y - 1 >= 0) { cScript.adjacents.Add(grid[x,y-1]); } if(y + 1 < size.y) { cScript.adjacents.Add(grid[x,y+1]); } } } }
I get the error on all the lines of codes that say cScript.adjacents.Add(etc.) The cScript that I take the variable adjacents is here:
#pragma strict
var adjacents : Transform[];
var position : Vector2;
var weightCell : int;
function Start () {
}
function Update () {
}
I haven't done much with the second script. Thanks for your help!
Answer by robertbu · Jul 23, 2014 at 06:08 AM
The built-in arrays are fixed size and do not support an Add() function. The usual recommendation for what you are doing is to use the .NET generic List class instead of built-in arrays. Here is a doc that describes the many collection types available to a Unity programmer:
http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use%3F
Your answer