I am having trouble spawning some obstacles from some prefabs. The aim is to make and endless runner (like normal) with obstacles to go through that spawn as the sprite goes up. But my prefabs don't spawn at the top?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RandomSpawn : MonoBehaviour
{
public GameObject B1, B2;
public float spawnrate = 2f;
float nextSpawn = 0f;
int whatToSpawn;
void Update()
{
if (Time.time > nextSpawn)
{
whatToSpawn = Random.Range(1, 3);
Debug.Log (whatToSpawn);
switch (whatToSpawn)
{
case 1:
Instantiate(B1, transform.position, Quaternion.identity);
break;
case 2:
Instantiate(B2, transform.position, Quaternion.identity);
break;
}
nextSpawn = Time.time + spawnrate;
}
}
}