An object won't spawn at main camera's Y-position

Here’s what my tiny 2D game works:

  • Main camera moves upward at the start
  • An object is main camera’s child
  • That object spawns a ground-prefab
  • A player must jump on grounds and dies if falling down

I made all of these and it works but I’m having a problem with an object. Prefabs are spawning at X-position at the same Y-position. I thought it should follow the camera’s Y-position? Here’s the script I copied:

Thank you and sorry for my english.

Nothing in this code follows the camera’s ‘y’ position. Since spawnValues is public, it is remotely possible that the intent is for another script is setting spawnValues.y to some some value. But if you want the camera ‘y’, just change the line to:

  Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), camera.main.transform.position.y, spawnValues.z);