i know it’s kinda of silly, but i just couldn’t figure out the correct way, here’s code I start
using UnityEngine;
using System.Collections;
public class MainChangeItems : MonoBehaviour {
// public GameObject prefab;
class item {
public int type;
public GameObject model;
}
public ArrayList items;
// Use this for initialization
void Start () {
GameObject prefab = FindObjectOfType(typeof("coat1m")) as GameObject;
GameObject obj;
items = new ArrayList();
obj = (GameObject)Instantiate(prefab,transform.position,transform.rotation);
obj.active = false;
item AItem=new item();
AItem.model = obj;
items.Add(AItem);
}
// Update is called once per frame
void Update () {
}
}
basically, if I have an instance of prefab in the scene, there’s no problem. But if I don’t have any in the scene, how do I instantiate this prefab by script ? Thanks a ton.
Fang