- Home /
Error in Spawning code
So here's the code
var enemy : GameObject; function Start () { while (true) { Instantiate (enemy, Vector3 (Random.Range (-20, 20), Random.Range (-20, 20), transform.position.z), transform.position, transform.rotation); yield WaitForSeconds (3);
}
}
and here's the error
Assets/Enemy/spawning.js(6,29): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.GameObject, UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Quaternion)' was found.
Any help?
Answer by GesterX · May 12, 2011 at 10:17 AM
The instantiate function expects a GameObject, followed by a Vector3, followed by a Quaternion for it's arguments. You have specified a GameObject, a Vector3, another Vector3, and a Quaternion.
I think in your case you should delete the transform.position (your 3rd argument). So your code will look like this:
Instantiate (enemy, Vector3 (Random.Range (-20, 20), Random.Range (-20, 20),
transform.position.z), transform.rotation);