Sorry, I don’t know why I couldn’t find this on the docs, but what function do I use to create a prefab at a certain coordinate?
Create an instance of a prefab? Unity - Scripting API: Object.Instantiate
Okay, with this, does the object need to be in the scene, or can it be created? I want to instantiate bullets.
Normally you create a prefab of the object. Then you have to fetch a reference to that object. (usually a public variable and drag and drop works fine) and this will instantiate it. You can also look at object pooling, depending on how your game function.
For instantiate, it doesn’t have to exist in the scene.
You need to create first a bullet, then make it a prefab. Then you can Instantiate the bullet even it is not on the scene.
public GameObject bulletPrefab;
then drag the bullet prefab to the variable bulletPrefab.
now you can Instantiate it with this
GameObject bullet = (GameObject)Instantiate (bulletPrefab, transform.position, transform.rotation);