(I am new to unity) I am trying to instantiate an object but I get this error ‘Vector3’ is an ambiguous reference between and ‘UnityEngine.Vector3’ . This is my code:
Instantiate(this.gameObject, new Vector3(53, randomYPos, 0));
(I am new to unity) I am trying to instantiate an object but I get this error ‘Vector3’ is an ambiguous reference between and ‘UnityEngine.Vector3’ . This is my code:
Instantiate(this.gameObject, new Vector3(53, randomYPos, 0));
First of all please copy the whole error message. The wording doesn’t sound like an actual error message. You can copy the error from the bottom half of the console window. Anyways if the error is what I think it is you might have created your own type / class called Vector3. While this is generally possible, inside Unity you should avoid naming your own types like built-in types. If for some reason you do need / want to do that, make sure you placed your own type inside your own namespace and only ever have either your namespace or UnityEngine in a using statement and never both.
A quick ad hoc solution would be to use new UnityEngine.Vector3( ...
instead of new Vector3( ...
.
Apart from that when you have a look at the Instantiate overloads available, you will notice that there is no version that only takes a source object and a Vector3. When you provide a position vector you also have to provide a rotation. Maybe that’s your actual issue.
You might be ‘using’ another namespace in your class that also contains Vector3.
There are conflicts when two namespaces have the objects by the same name like Math and UnityEngine both have the ‘Random’ class so if you have
using UnityEngine;
using Unity.Math;
at the top of your class, calling random will call one or the other but you won’t know which unless you specifically call the namespace you want like
Unity.Math.Random
That said, to make your call to ‘Vector3’ work, you can write
Instantiate(this.gameObject, new UnityEngine.Vector3(53, randomYPos, 0));