- Home /
.Add not a function of my array.
i have this array of my "Buff" class (or at least i thought it was.)
var buffs: Buff[];
then later when i try to add a buff to the array:
buffs.Add(newBuff);
and it says .Add is not a member of "Buff[]". i must have created the array wrong? but i'm not sure how.
Answer by clunk47 · Nov 26, 2013 at 06:17 AM
You should be using a Generic List.
#pragma strict
import System.Collections.Generic;
var buffs : List.<Buff> = new List.<Buff>();
function Start()
{
buffs.Add(newBuff);
}
Not sure what newBuff is, or if you were trying to add (new Buff)... If you still have troubles, I'll need to see your Buff class.
my buff class just has some simple variables in it like strings and floats. but i think i have it working the way i need now, thanks for the heads up with the list!
Your answer
Follow this Question
Related Questions
adding object to builtin array works in one script, not in another? 1 Answer
Array doesn't increase or add element 1 Answer
Array of GameObjects 4 Answers
Removing objects from an array 2 Answers
array of objects 1 Answer