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

  • \$\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
    Commented Aug 12, 2016 at 6:41
  • \$\begingroup\$ Thanks @Droppy, I'm still getting the error message though \$\endgroup\$
    – Alex Carr
    Commented Aug 12, 2016 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
    Commented Aug 12, 2016 at 6:47

1 Answer 1


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.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .