Hello! Im making a 2D endless runner where objects spawn randomly. The objects currently spawn in the middle of the screen. How would I edit the screen bounds so it appears they spawn in front of the character (far right)? Here is my code!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TrashSpawner : MonoBehaviour
{
public GameObject Cheese;
public float spawnDelay = 1f;
public float spawnTime = 4f;
public int numberToSpawn;
public List<GameObject> spawnPool;
public GameObject quad;
void Start()
{
InvokeRepeating("spawnObjects", spawnDelay, spawnTime);
Vector3 position = new Vector3(5.0f, 0, 0);
Cheese.transform.position += position;
Vector3 position1 = new Vector3(0, 1, 0);
Cheese.transform.position += position1;
}
public void spawnObjects()
{
//destroyObjects();
int randomItem = 0;
GameObject toSpawn;
MeshCollider c = quad.GetComponent<MeshCollider>();
float screenX, screenY;
Vector2 pos;
for (int i = 0; i < numberToSpawn; i++)
{
randomItem = Random.Range(0, spawnPool.Count);
toSpawn = spawnPool[randomItem];
screenX = Random.Range(c.bounds.min.x, c.bounds.max.x);
screenY = Random.Range(c.bounds.min.y, c.bounds.max.y);
pos = new Vector2(screenX, screenY);
Instantiate(toSpawn, pos, toSpawn.transform.rotation);
}
}
}
Thanks!