Hi All,
I have some code which I would like to spawn a monster. Here’s a snippet of my code:
________________________
public var prefab : PrefabType;
public var spawnPlace : GameObject;
// ........ (a lot of other stuff)
Instantiate(prefab, spawnPlace.transform.position, transform.rotation)
________________________
And then I get an error:
BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEditor.PrefabType, UnityEngine.Vector3, UnityEngine.Quaternion)' was found.
I’m guessing that’s because I’m using a variable type PrefabType
rather than GameObject
, but in my game my enemies only move in one direction, and I’ve made some code,
if (transform.position.x < **A Certain Point**){
Destroy(gameObject);
}
which destroys my enemies after they get off the edge of the screen, but if I Instantiate
a GameObject
, after a while, the “spawn object” will go past the “certain point” and no more will spawn, so that’s why I want to Instantiate
a Prefab.
Does anyone know how to Instantiate
a prefab? Any help would be much appreciated.
(If its not clear, I’m a beginner with Unity, and I’m trying to get my head around the Instantiate
function/command/thingy.)