- Home /
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.
Never$$anonymous$$d, you can't use a Vector3 for the rotation part... Sorry...
Answer by Uriel_96 · Nov 23, 2010 at 11:19 PM
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);
Answer by Eric5h5 · Nov 23, 2010 at 11:24 PM
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.
Your answer
Follow this Question
Related Questions
[Closed]NullReferenceException on Object Instantiation onto game world 2 Answers
Instantiate and Scaling 0 Answers
need help with instantiate'ing a Rigidbody 1 Answer
Duplicating meshes without instantiating? 2 Answers
How can I replace an object while keeping the references to that object? 2 Answers