Hi! I’m trying to remake the Flappy Bird game but I have one small problem: The pipes won’t spawn. The thing is that in unity works fine but on android nothing is spawned.
Here is my code for the spawning mechanism:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PipeSpawner : MonoBehaviour
{
public static PipeSpawner Instance;
public float maxTime = 0.5f;
private float timer = 0;
public float height = 1.5f;
public List<Transform> pipeList;
public GameObject pipe;
// Start is called before the first frame update
void Awake()
{
pipeList = new List<Transform>();
if (Instance == null)
{
Instance = this;
}
}
void Start()
{
GameObject newPipe = Instantiate(pipe);
newPipe.transform.position = transform.position + new Vector3(0, Random.Range(-height, height), 0);
pipeList.Add(newPipe.transform);
}
// Update is called once per frame
void Update()
{
if (timer > maxTime)
{
GameObject newPipe = Instantiate(pipe);
//pipeObject.position += new Vector3(-1, 0, 0) * GameControl.Instance.scrollSpeed * Time.deltaTime;
newPipe.transform.position = transform.position + new Vector3(0, Random.Range(-height, height), 0);
timer = 0;
pipeList.Add(newPipe.transform);
}
timer += Time.deltaTime;
}
}
I also have a small script for the pipes to move them and destroy them:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PipeControl : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.position += new Vector3(-1, 0, 0) * GameControl.Instance.scrollSpeed * Time.deltaTime;
if (transform.position.x < -14.96f)
{
Destroy(transform.gameObject);
}
}
}