x


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

more ▼

asked Jul 14 '12 at 03:28 PM

Lukas Barbarossa gravatar image

Lukas Barbarossa
22 4 6

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

The third parameter is a Quaternion - so you would need:

  var newZombie = Instantiate(zombiePrefab, zombieSpawnPoint, Quaternion.Euler(zombieSpawnRotation));
more ▼

answered Jul 14 '12 at 03:33 PM

whydoidoit gravatar image

whydoidoit
32.9k 11 23 98

SOLVED Thanks Mike. 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.

Jul 14 '12 at 09:45 PM Lukas Barbarossa
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1938
x1668
x1250
x652
x438

asked: Jul 14 '12 at 03:28 PM

Seen: 311 times

Last Updated: Jul 14 '12 at 09:45 PM