- Home /
Question by
Scrabblem · Dec 04, 2018 at 03:01 PM ·
arraygameobjects
Adding a created GameObjects to a array.
Hello, i have a problem, in a script i created a object based on the class and this object i would like to add to my array, but i can't:( This is the code that i thought should work but it doesnt:(
void Start ()
{
//here i created a object based on a Weapon class
Weapon bron = new Weapon();
//here i wanted to add a created object to a array, but it doesn't work i have a CS0029 error
weapon[0] = bron;
Debug.Log(weapon[0].hp);
}
Comment
Best Answer
Answer by ecv80 · Dec 04, 2018 at 03:08 PM
What that error is saying is, your array is a different type than Weapon.
If your array is similar to this: Weapon[] weapon=new Weapon[5];
it should work.
Oh yes, i made a bad declaration of a array, with this it works:) Thank you