So I decided to make a game for a school project just for fun, it’s a typical fly around dodge asteroids 2d game. I have run into one problem though. I have created an empty game object with a square that shows the “spawnable” area for the asteroids. But when I move and the camera/the empty game object updates its position. The spawn area for the asteroids won’t, the square will follow the change in position but the asteroids won’t.
I have pasted my script that is basically copied from a youtube video and I will also link a youtube video that I recorded to show more in-depth what I mean
Thanks in advance
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class deployDodgebles : MonoBehaviour
{
public GameObject circlePrefab;
public Transform positionSpawner;
public GameObject circles;
public float respawnTime = 1;
private void Start()
{
StartCoroutine("respawnEnemie");
}
private void spawnEnemie()
{
circles = Instantiate(circlePrefab) as GameObject;
circles.transform.parent = positionSpawner.transform;
circles.transform.position = new Vector2(Random.Range(-13.49813f, 13.49813f), 7.347601f);
}
IEnumerator respawnEnemie()
{
while (true)
{
yield return new WaitForSeconds(respawnTime);
spawnEnemie();
}
}
private void OnBecameInvisible()
{
Destroy(circles.gameObject);
}
}