- Home /
Problem with adding 1 element of an array to a list
well the tiltle says it here is the error i get: Assets/scripts/AddItem.js(29,28): BCE0048: Type 'System.Type' does not support slicing.
here is the script where the item is what i want to add.
#pragma strict
import System.Collections.Generic;
var Inventory : PlayerInv;
var GUISKIN : GUISkin;
var Weapons : WeaponInfo[];
class WeaponInfo
{
var GO : GameObject;
var name : String;
var icon : Texture2D;
}
function Start ()
{
Inventory = GetComponent(PlayerInv);
}
function OnGUI()
{
GUI.skin = GUISKIN;
for(var Weapon : WeaponInfo in Weapons)
{
GUILayout.Label(Weapon.icon, GUILayout.Width(300));
if (GUI.Button(Rect(0,0,306,156),""))
{
Debug.Log("You Choose The AKS74U");
Inventory.Inv.Add(WeaponInfo[0]);
}
}
}
here is the script where i want to add it to:
import System.Collections.Generic;
var Inv = List.<itemclass>();
function Start () {
}
function Update () {
}
Comment
Best Answer
Answer by save · Sep 02, 2013 at 02:44 PM
You're trying to add the class WeaponInfo
with a slicing, instead of the variable at Weapons[0]
.
Inventory.Inv.Add(Weapons[0]);
Also do note that the list Inv is of type itemclass
, the thing you're trying to add is of type WeaponInfo
.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Concat() for Lists 1 Answer
Can´t instantiate objects in list correctly 1 Answer
2D GameObject Array to 2D List 1 Answer
Problem with List not filling using add method in a foreach loop 1 Answer