- Home /
Enemy not spawning correctly
Hello. Sorry for posting such a similar question to others, but it seems the answers I can find tell me there is nothing wrong with my script. I'm sure I am missing something obvious (newbie alert).
I have the following code on my Main Camera, so it should happen straight away
var zombiePrefab :Transform; //my zombie prefab is dragged onto this in Inspector
var zombieSpawnPoint = Vector3(99, 15, 36);
var zombieSpawnRotation = Vector3(0, 0, 0);
function Start(){
var newZombie = Instantiate(zombiePrefab, zombieSpawnPoint, zombieSpawnRotation);
}
Instead of a zombie I get the following error
> BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.GameObject, UnityEngine.Vector3, UnityEngine.Vector3)' was found
I would really appreciate any help. I just can't see what I have done. If I had to guess from the error message, I'd say it wants my prefab to be a GameObject not a Transform, but that isn't right.... is it?
Thanks in advance
Answer by whydoidoit · Jul 14, 2012 at 03:33 PM
The third parameter is a Quaternion - so you would need:
var newZombie = Instantiate(zombiePrefab, zombieSpawnPoint, Quaternion.Euler(zombieSpawnRotation));
SOLVED Thanks $$anonymous$$ike. Worked perfectly, and another piece of the Unity puzzle fits into place. Would like to vote your answer up, but apparently I can't with his login, despite using it for the original post.
Your answer
Follow this Question
Related Questions
Error: Instantiated Enemies don't get hit 2 Answers
How to spawn a 'boss' after all enemies defeated and then kill that 'boss'? 1 Answer
Instantiate with Prefabs 2 Answers
Destroy and Spawn an Enemy 1 Answer
Instantiated enemy looks at player 1 Answer