Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question syntax Error, ',' expected but im not actually missing anything

Discussion in 'Scripting' started by PsycoticFish, Nov 9, 2023.

  1. PsycoticFish

    PsycoticFish

    Joined:
    Nov 6, 2023
    Posts:
    2
    So I'm following the Unity learn tutorial, but it says my code is missing a ','. I've compared, and my code is identical to the example. I have to complete this for a project in class, but I'm kind of lost. It also says the error is on line 30 col 71. Pictures for reference Lesson 2.4 - Collision Decisions - Unity Learn - Google Chrome 11_9_2023 2_02_48 PM.png SpawnManager.cs - Visual Studio Code 11_9_2023 2_02_23 PM.png
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,278
    EDIT: Wow, Unity's site here:

    https://connect-prd-cdn.unity.com/2...b60_Lesson_Plan_2.4___Collision_Decisions.pdf

    Has an egregious error in the code.

    The corrected code should read:

    Code (csharp):
    1.         void SpawnRandomAnimal()
    2.         {
    3.             Vector3 spawnpos = new Vector3(
    4.                 Random.Range(-xSpawnRange, xSpawnRange), 0, zSpawnPos);
    5.             int animalIndex = Random.Range(0, animalPrefabs.Length);
    6.             Instantiate(animalPrefabs[animalIndex], spawnpos,
    7.                 animalPrefabs[animalIndex].transform.rotation);
    8.         }
    Can someone like @MelvMay perhaps escalate?

    The INCORRECT code reads:

    Code (csharp):
    1. Instantiate(animalPrefabs[animalIndex], new Vector3(0, 0, 20) spawnpos,
    2.       animalPrefabs[animalIndex].transform.rotation);
    and thus has the extra Vector3 expression immediately before the spawnpos argument.
     
    Last edited: Nov 9, 2023
  3. PsycoticFish

    PsycoticFish

    Joined:
    Nov 6, 2023
    Posts:
    2
    alr, thanks for the advice! and I'll make sure to use proper tags/formatting next time
     
  4. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,576
    I think there's probably supposed to be a "," between
    new Vector3(0, 0, 20)
    and
    spawnpos
    . These are two separate things.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,278
    Read again... that would be supplying TWO Vector3s to Instantiate<T>(), which as last I checked was not a supported overload. :)

    It really is an error in the Unity PDF / Learn site.