x


Instantiate GameObjects, brings an error to the log...

var Monster : GameObject[]; 


function Update () 
{
    for(var i=0; i<Monster.length; i++)
    {
        Instantiate(Monster[i], Vector3(250, 5, 5), Vector3(180, 0, 0));
        yield WaitForSeconds (60);
    }
}

That's the code.

Error is: BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.GameObject, UnityEngine.Vector3, UnityEngine.Vector3)' was found.

Any help would be great, thanks, JUstin W.

more ▼

asked Nov 23 '10 at 10:53 PM

Justin Warner gravatar image

Justin Warner
6.3k 19 27 65

Nevermind, you can't use a Vector3 for the rotation part... Sorry...

Nov 23 '10 at 11:05 PM Justin Warner
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

your rong to put double vector3(because is a distance).

 Instantiate (Monster[i], Vector3(250, 5, 5), Quaternion.identity);

The right order is to put the object then the distance and then the rotation. For the rotation you can put also:

Instantiate (Monster[i], Vector3(250, 5, 5), transform.rotation);
more ▼

answered Nov 23 '10 at 11:19 PM

Uriel_96 gravatar image

Uriel_96
930 61 70 81

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

The third parameter, rotation, is a quaternion rather than a Vector3. You can convert a Vector3 to a quaternion like so:

Instantiate(Monster[i], Vector3(250, 5, 5), Quaternion.Euler(Vector3(180, 0, 0)));

Also, Update runs once every single frame, and can't be delayed or interrupted. Therefore it can't be a coroutine and can't use yield. Start can be a coroutine, so put your loop in Start instead.

more ▼

answered Nov 23 '10 at 11:24 PM

Eric5h5 gravatar image

Eric5h5
80.1k 41 132 519

(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:

x1946
x1670
x1092
x41

asked: Nov 23 '10 at 10:53 PM

Seen: 3566 times

Last Updated: Nov 23 '10 at 10:53 PM