Add prefab to gameObject

Hi everyone,

I have a question that keeps bothering me.

I have a script on a player called Inventory. This script contains an array for Weapons. During run time I want to add a new weapon to this array.

//inventory script
public Weapon[] inventory;
    void Start()
    {
        inventory = new Weapon[3];
        inventory[0] = new Gun1();

However, the weapon has all kinds of public attributes that I want to fill in via the editor. For instance, every weapon has an attribute for an weapon icon. I want an artist to fill in these attributes via the editor. But then I need to attach the script to an object in order to fill in these attributes.

//Gun1 script
public Texture2D weaponIcon;

What is a good approach to assign an icon to, for instance, a prefab with the gun script on it and then adding this prefab to the array? So that the array can acces the prefabs gun icon?

I hope the question is clear. thanks in advance for your answer.

I am sure you have it, drop in the script that contains the class: Weapon

There are two things that have to happen:

First, you have to add the weaponIcon variable to your Weapon class

Second, you have to define how that icon is used in the GUI

I would use an ArrayList instead of the standard array. There are a few extra methods in it that will help you along. (i.e. Add, IndexOf and Remove)

okay, thanks for the help.