Question about Vector3 usage

Hello!
In my little script I created a Vector3 array to assign random spawnPoints:

    public Vector3[] spawnPoints;

(even this little line of code gives me an error sometimes: System.Numerics.Vector3 or Unity.Engine.Vector3? - Ambiguous!)

Then I wrote something like this:

private void CreatePlayer()
    {
        int NumeroSpawnPoints = spawnPoints.Length;
        int RandomSpawnPoint = Random.Range(0, NumeroSpawnPoints);

        switch (RandomSpawnPoint)
        {
            case 0:
                UnityEngine.Vector3 posizione = spawnPoints[0];
                break;

            case 1:
                UnityEngine.Vector3 posizione = spawnPoints[1]);
                break;
            case 2:
                UnityEngine.Vector3 posizione = spawnPoints[2];
                break;
        }

But it does not work …

How can I assign a Vector3 value that I can later use on an Instantiate?
My Idea was to pick a random Vector3 and assign it to “posizione” and then use something like

 PhotonNetwork.Instantiate(Path.Combine("Personaggio3", "3"), posizione, Quaternion.identity, 0);

How can I achieve this?

Thanks for your help! (I will be back to my computer in 12H so I can’t try right now!)

P.s.
How can I also get rid of that “ambiguous” error?

Do I have to code it like
UnityEngine.Vector3 ?

You have this at the top of your script:

using System.Numerics;

Simply remove it.

The “ambiguous” error means that two or more namespaces you’re using have the same identifier names.
In your case, there is something named “Vector3” in the UnityEngine namespace, as well as in the System.Numerics namespace, thus, it cannot be determined which “Vector3” you meant to refer to unless you explicitly type out “UnityEngine.Vector3” or “System.Numerics.Vector3”.

For your second issue, we need more information other than “it doesn’t work”.

Besides that, you can get rid of that switch statement entirely and just do this instead to select a random index from an array:

private void CreatePlayer()
{
   int RandomSpawnPoint = Random.Range(0, spawnPoints.Length - 1);
   Vector3 posizione = spawnPoints[RandomSpawnPoint];
}
1 Like

First of all, Thank you, Vryken!
Well Yes, I was a dumb coding that switch! I don’t know why I did not used your way!

Of course, now I get rid of all errors. Errors were related to the fact I was declaring every time a
“Vector3 posizione” in each Switch case. Now I have just one declaration:

Vector3 posizione = spawnPoints[RandomSpawnPoint];

and for VisualStudio, that’s fine.

Now I have to see if code will work as I hope!

Thank you so much!

Just to note for the future, the best place for scripting questions is the scripting forum. This forum is for 2D feature support.