0
\$\begingroup\$

So I'm trying to make a little game where squares randomly spawn around a set area and you have to tap them. The game is 2D. I'm having trouble using my randomly generated x and y floats to instantiate a cube in the game. Here is my code:

#pragma strict

public var play = false;
public var xpos : float;
public var ypos : float;
public var cube : GameObject;

function Start () {

}

function Update () {
}

function Game () {
    xpos = Random.Range(-10f,10f);
    ypos = Random.Range(-4.45f,4.45f);
    Instantiate(cube, new Vector2(xpos, ypos));
}

And here's the error!

Assets/gameController.js(18,20): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.Rigidbody, UnityEngine.Vector2)' was found.

Any help would be appreciated. Thanks! -Alex

\$\endgroup\$
3
  • \$\begingroup\$ cube should be a GameObject (the prefab of the thing to spawn), but a Rigidbody. Also the other parameters don't match any Object.Instantiate() signature. \$\endgroup\$
    – Droppy
    Aug 12 '16 at 6:41
  • \$\begingroup\$ Thanks @Droppy, I'm still getting the error message though \$\endgroup\$
    – Alex Carr
    Aug 12 '16 at 6:43
  • \$\begingroup\$ Hold on... Thanks @Droppy, I looked up the signature and found that I was just mission Quaternion.Idenity \$\endgroup\$
    – Alex Carr
    Aug 12 '16 at 6:47
-1
\$\begingroup\$

After a bit of help from @Droopy I was able to figure out the solution. I was simply missing a few arguments from the Instantiate function.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.