Previously I asked question and got proper solution for adding and destruction 3D object at run time.
By using GameObject.CreatePrimitive(PrimitiveType.Capsule); I can add only limited 3D object like Cube , Capsules and other
Now the problem is, I want add 3D human body .fxb object. Can I add .fbx object in below code?
Queue<GameObject> Capsules;
void Start()
{
Capsules = new Queue<GameObject>();
}
public GameObject caps;
private void createObject()
{
caps = GameObject.CreatePrimitive(PrimitiveType.Capsule);
Capsules.Enqueue(caps);
}
You can do this by using prefabs. After you created your prefab in the editor you can use it in scripts using the following code:
after you have your prefab loaded you can make copies using
Instantiate
.Long story short: YOU CAN'T!
GameObject.CreatePrimitive
only creates primitives, like cubes cylinders etc. If you want to instantiate your prefab at runtime, I suggest you go look atInstantiate
.You can do this instead: