I have a problem. When I build my game to android and deploy it to a device, some objects don’t spawn at all.
The game basically spawns boxes and moves them towards the player and the player has to avoid them. The boxes don’t spawn on phones, but it does when I test it on my computer. I have no idea what is going on. Below is my spawning script. It used to work before, I don’t what happened.
public class Randomize : MonoBehaviour {
// --- Variable Declaration --- //
public GameObject Prefab;
public float objectsPerSecond = 5;
public float MaxDistance = 5.0f;
public float spawnTimer = 5;
// Spawn Objects
private void spawn()
{
// loop based on how many objects to spawn per second
for(int i = 0; i < objectsPerSecond; i++)
{
// Y axis
float height = Random.Range(-4.0f, 4.0f);
// X axis
float distance = Random.Range(0, MaxDistance);
// clone the objects
Instantiate(Prefab);
// move the objects
Prefab.transform.position = new Vector2(10 + distance, height);
}
}
void Start()
{
// call the spawn method to spawn the boxes.
InvokeRepeating ("spawn", spawnTimer, spawnTimer);
}
}