Quaternian can't be converted to float. What to use instead?

here is my error:
“error CS1503: Argument #2' cannot convert UnityEngine.Quaternion’ expression to type `float”

and here is my code

public float delay = 1.0f;
    public GameObject cube;

    void Start () {
        InvokeRepeating ("Spawn", delay, delay);
   
    }

    void Spawn(){
        Instantiate (cube, new Vector3(Random.Range(-3,3), Quaternion.identity) );
    }

i got this from a tutorial in youtube,

and it wont work in unity 5,what should i replace this with? im a newbie,thanks!

It’s just wrong :slight_smile: Watch the tutorial again and copy the code that he actually uses.

1 Like

new Vector3(Random.Range(-3,3), Quaternion.identity)

Is just incorrect code entirely.

The parameters for Vector3 are (float, float, float) and you have used (float, quaternion, nothing) so obviously, it’s not going to work out with those typos.

And that Random.Range lacks f, so the returned value will most likely be rounded to int.

remove new before new Vector3(Random.Range(-3,3)
create Vector3 pos = new Vector3(0, 0, 0);
Instantiate (cube, pos, Quaternion.identity);

here is a sample,

void Start()
{
Vector3 pos = new Vector3(0, 0, 0);

for (int i = 0; i < 20; i++)
{
//Instantiate(platform, new Vector3(i, pos, Quaternion.identity)); //----Doesnt work
Instantiate(platform, pos, Quaternion.identity); //----Does work
pos.z += 10;

}
}

#JaQDaW
#Just a quick and dirty way

@troynall , thanks for being helpful, but please look at the dates of posts you’re replying. The last post in the thread was from over seven years ago. And also use code tags when you post code.

1 Like

Locking this thread – please create a new thread if you wish to continue

1 Like