Noob question. But i’m working on this project for class, a “kaboom” like game. Where as the top moving object, the computer(in this case it’s also a UFO) spawns spheres(or bombs in this case) from it as it moves. The spheres fall to the bottom of the screen. You have to catch them with a platform. But all I want to know is how to spawn them from the UFO object. I looked up instantiate and prefabs, but am a little confused. Will appreciate any help. Thanks.
So, prefabs are assets in your project folder containing a gameObject and it’s hierarchy you want to re-use. It’s actually a GameObject saved on the computer.
Now, the Instantiate function can copy a GameObject, for example that prefab. So, in your UFO, add in your script and drag drop the Bomb prefab on the variable (in the inspector):
JS :
var prefab : GameObject;
function CreateBomb(){
// That will copy the prefab into the scene at the UFO position
// and without rotation, just as if you dragged it in
// You don't have to affect it to a var, unless you need to.
var bomb: GameObject = Instantiate( prefab,
transform.position, Quaternion.identity;
}
C# (must be inside a class inheriting from MonoBehaviour:
GameObject prefab;
public void CreateBomb(){
GameObject bomb = Instantiate( prefab,
transform.position, Quaternion.identity;
}