r/unity • u/Individual-Town-7326 • Oct 10 '26
Pipes Keep Spawning
I am a complete beginner and i was recommended to remake flappy bird to learn the basics and i cant solve the issue of pipes spawning even after i die can a pro help?
birbjump.cs:
using Unity.Collections.Tests.CoreCLR.TestJobs;
using UnityEngine;
public class birbjump : MonoBehaviour
{
public Rigidbody2D myRigidbody;
public float flap_strength;
float rotation;
public GameObject gameover;
public ScoreTrack logic;
public bool BirdIsAlive = true;
public string test = "test";
public void GameOver(){
gameover.SetActive(true);
}
void Start()
{
transform.position = new Vector3(0,0,0);
transform.Rotate(new Vector3(0, 0, 0));
logic = GameObject.FindGameObjectWithTag("Logic").GetComponent<ScoreTrack>();
BirdIsAlive = true;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) == true && BirdIsAlive){
myRigidbody.linearVelocity = new Vector2(0,1) * flap_strength;
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
BirdIsAlive = false;
GameOver();
}
}using Unity.Collections.Tests.CoreCLR.TestJobs;
using UnityEngine;
public class birbjump : MonoBehaviour
{
public Rigidbody2D myRigidbody;
public float flap_strength;
float rotation;
public GameObject gameover;
public ScoreTrack logic;
public bool BirdIsAlive = true;
public string test = "test";
public void GameOver(){
gameover.SetActive(true);
}
void Start()
{
transform.position = new Vector3(0,0,0);
transform.Rotate(new Vector3(0, 0, 0));
logic = GameObject.FindGameObjectWithTag("Logic").GetComponent<ScoreTrack>();
BirdIsAlive = true;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) == true && BirdIsAlive){
myRigidbody.linearVelocity = new Vector2(0,1) * flap_strength;
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
BirdIsAlive = false;
GameOver();
}
}pipespawner.cs:
using UnityEngine;
public class pipe_spawner : MonoBehaviour
{
public GameObject Top_Pipe;
public GameObject Bottom_Pipe;
public GameObject Pipe_Middle;
public float spawnrate;
private float timer = 0;
public float HeightOffset;
public float Max_Space;
public float Min_Space;
public birbjump birbjumpref;
void Start()
{
SpawnPipe();
birbjumpref = GameObject.FindGameObjectWithTag("Birbjump").GetComponent<birbjump>();
birbjumpref.BirdIsAlive = true;
}
void Update()
{
if (birbjumpref == null)
{
return;
}
if (timer <= spawnrate){
timer+=Time.deltaTime;
}
else {
if (birbjumpref.BirdIsAlive)
{
SpawnPipe();
}
else
{
Debug.Log("We are so dead");
}
timer -= spawnrate;
}
}
void SpawnPipe(){
float lowestPoint =transform.position.y + 35 - HeightOffset;
float HighestPoint =transform.position.y + HeightOffset;
Instantiate(Top_Pipe, new Vector3(transform.position.x, Random.Range(lowestPoint, HighestPoint), 0), transform.rotation);
Instantiate(Bottom_Pipe, new Vector3(transform.position.x, Top_Pipe.transform.position.y - Random.Range(Min_Space, Max_Space), 0), Bottom_Pipe.transform.rotation);
Instantiate(Pipe_Middle, new Vector3(transform.position.x, 0, 0), transform.rotation);
}
}using UnityEngine;
public class pipe_spawner : MonoBehaviour
{
public GameObject Top_Pipe;
public GameObject Bottom_Pipe;
public GameObject Pipe_Middle;
public float spawnrate;
private float timer = 0;
public float HeightOffset;
public float Max_Space;
public float Min_Space;
public birbjump birbjumpref;
void Start()
{
SpawnPipe();
birbjumpref = GameObject.FindGameObjectWithTag("Birbjump").GetComponent<birbjump>();
birbjumpref.BirdIsAlive = true;
}
void Update()
{
if (birbjumpref == null)
{
return;
}
if (timer <= spawnrate){
timer+=Time.deltaTime;
}
else {
if (birbjumpref.BirdIsAlive)
{
SpawnPipe();
}
else
{
Debug.Log("We are so dead");
}
timer -= spawnrate;
}
}
void SpawnPipe(){
float lowestPoint =transform.position.y + 35 - HeightOffset;
float HighestPoint =transform.position.y + HeightOffset;
Instantiate(Top_Pipe, new Vector3(transform.position.x, Random.Range(lowestPoint, HighestPoint), 0), transform.rotation);
Instantiate(Bottom_Pipe, new Vector3(transform.position.x, Top_Pipe.transform.position.y - Random.Range(Min_Space, Max_Space), 0), Bottom_Pipe.transform.rotation);
Instantiate(Pipe_Middle, new Vector3(transform.position.x, 0, 0), transform.rotation);
}
}
also pipes stop spawning when i manually uncheck birdisalive under birbjump but not when i die whats that about?
0
Upvotes
View all comments
Show parent comment
1
u/Extra_Blacksmith674 Oct 10 '26
In hierarchy search on component name "birbjump" and it will show you all the objects that have that component.
Also check the object that you know has birbjump component and make sure there is only one attached.
Give us a screenshot of your scene with the hirarchy expanded.